[Issue 21590] assignment inside assert accepted if -checkaction=context is given

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Jan 29 11:47:31 UTC 2021


https://issues.dlang.org/show_bug.cgi?id=21590

moonlightsentinel at disroot.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |moonlightsentinel at disroot.o
                   |                            |rg
           Hardware|x86_64                      |All
                 OS|Linux                       |All

--- Comment #1 from moonlightsentinel at disroot.org ---
That's an unintended consequence of the current rewrite for expressions with
side effects. The compiler lowers the example to:

unittest
{
        int a = 0;
        int b = 1;
        (ref int __assertOp2 = a = b;) , assert(__assertOp2,
_d_assert_fail(__assertOp2));
}

The assignment happens for the temporary and hence becomes legal. The compiler
should probably check if the expression can be used as a condition before the
rewrite.

--


More information about the Digitalmars-d-bugs mailing list