[Dlang-internal] Detect CTFE in AssignExp:semantic

Walter Bright via Dlang-internal dlang-internal at puremagic.com
Mon Jan 16 19:32:41 PST 2017


On 1/16/2017 2:09 PM, Lucia Cojocaru wrote:
> ptrdiff_t f(char[] s) {
>     // foreach(c; s) if (c == '.') return 0; // (0)fails with the same error
> message
>     foreach(char c; s) if (c == '.') return 0; // (1)
>     // foreach(dchar c; s) if (c == '.') return 0; // (2) different compile
> path, doesn't fail
>
>     /*
>     for (size_t i = 0; i < s.length; i++)
>     {
>         if (s[i] == '.') return i;
>     }
>     */
>     return -1;
> }
>
> pragma(msg, f(['z', 'b', 'c', '.', 'd']));

I just compiled it with:

    dmd -c bug8

and it prints:

    0

with no error message.


More information about the Dlang-internal mailing list