Thread overview
[Issue 24582] Detect unsafe `cast(bool[])`
[Issue 24582] Detect unsafe casting to bool
Jun 03, 2024
Nick Treleaven
Jun 03, 2024
Dlang Bot
Jun 03, 2024
Dennis
Jun 03, 2024
Nick Treleaven
Jun 03, 2024
Nick Treleaven
Jun 05, 2024
Nick Treleaven
Jun 13, 2024
Dlang Bot
June 03, 2024
https://issues.dlang.org/show_bug.cgi?id=24582

Nick Treleaven <nick@geany.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |safe

--
June 03, 2024
https://issues.dlang.org/show_bug.cgi?id=24582

Dlang Bot <dlang-bot@dlang.rocks> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull

--- Comment #1 from Dlang Bot <dlang-bot@dlang.rocks> ---
@ntrel created dlang/dmd pull request #16558 "Fix Bugzilla 24582 - Detect unsafe casting to bool" fixing this issue:

- Fix Bugzilla 24582 - Detect unsafe casting to bool

https://github.com/dlang/dmd/pull/16558

--
June 03, 2024
https://issues.dlang.org/show_bug.cgi?id=24582

Dennis <dkorpel@live.nl> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dkorpel@live.nl
           Hardware|x86_64                      |All
                 OS|Linux                       |All

--- Comment #2 from Dennis <dkorpel@live.nl> ---
These casts only produce safe values 0 and 1 right?

--
June 03, 2024
https://issues.dlang.org/show_bug.cgi?id=24582

Nick Treleaven <nick@geany.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|Detect unsafe casting to    |Detect unsafe
                   |bool                        |`cast(bool[])`

--
June 03, 2024
https://issues.dlang.org/show_bug.cgi?id=24582

--- Comment #3 from Nick Treleaven <nick@geany.org> ---
    bool v = cast(bool) 2;

    ubyte[] a = [2, 4];
    auto b = cast(bool[]) a;
    auto c = cast(bool[]) [2, 4]; // literal cast

    import std.stdio;
    writeln(*cast(byte*)&v); // 1, OK
    writeln(*cast(byte*)b.ptr); // 2, unsafe
    writeln(*cast(byte*)c.ptr); // 1, OK

So only the runtime array cast is unsafe.

--
June 05, 2024
https://issues.dlang.org/show_bug.cgi?id=24582

Nick Treleaven <nick@geany.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://issues.dlang.org/sh
                   |                            |ow_bug.cgi?id=20148

--
June 13, 2024
https://issues.dlang.org/show_bug.cgi?id=24582

Dlang Bot <dlang-bot@dlang.rocks> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #4 from Dlang Bot <dlang-bot@dlang.rocks> ---
dlang/dmd pull request #16558 "Fix Bugzilla 24582 - Detect unsafe `cast(bool[])`" was merged into master:

- 04bd8b21ee11f7ab16d8dc97c28a5b37365db89f by Nick Treleaven:
  Fix Bugzilla 24582 - Detect unsafe `cast(bool[])`

  Allow literal cast

  Make deprecation

  Add specific supplemental message

https://github.com/dlang/dmd/pull/16558

--