[Issue 14387] Disallow string literals as assert conditions
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Sat Apr 4 20:49:31 PDT 2015
https://issues.dlang.org/show_bug.cgi?id=14387
Vladimir Panteleev <thecybershadow at gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |thecybershadow at gmail.com
--- Comment #2 from Vladimir Panteleev <thecybershadow at gmail.com> ---
(In reply to Don from comment #1)
> IMHO it's also pretty weird that string literals are implicitly convertable
> to bool. Note that they weren't convertable in D1: assert("abc"); and
> if("abc") both generated compile-time errors. I don't think that was an
> intentional change, but I could be wrong.
For non-static assert, D1 and D2 pre 2.023 say:
test.d(4): Error: expression "test" of type invariant(char[4u]) does not have a
boolean value
>From 2.023 changelog:
"the type of a string literal is now invariant(char)[] rather than
invariant(char)[length_of_string]. It is still implicitly convertible to the
latter. This is intended to reduce template instantiation bloat."
This is a case of dynamic arrays implicitly converting to bool whether they're
null or non-null. So, this will automatically be "fixed" when implicit
array-to-bool conversion is deprecated (
https://github.com/D-Programming-Language/dmd/pull/2885 ).
--
More information about the Digitalmars-d-bugs
mailing list