[Issue 11080] assert(`string`) should be forbidden

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Sep 21 14:29:21 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=11080



--- Comment #17 from Maxim Fomin <maxim at maxim-fomin.ru> 2013-09-21 14:29:19 PDT ---
(In reply to comment #12)
> (In reply to comment #11)
> > Assert("string") is a bug. There should be no discussion here.
> 
> Why is it a bug? That's the discussion we're having. An array literal that
> evaluates to null *will* trigger it. A user can test it.
> 
> void main()
> {
>     enum string s1 = "string";
>     enum string s2 = null;
> 
>     assert( s1);
>     assert(!s2);
> 
>     assert( "");
>     assert(!string.init);
> }
> 
> These all seem like legit use cases to me.

No, there is difference between array type object and array literal expression.
Code like assert("Array literal") (note that this is not assert(s) where 's'
refers to a string) is always a bug because the expression is always true and
indicates that user actually wanted assert(some_condition, "array literal").
There is no reason to write such code. As I have pointed out above, even in
situations which are not surely error, dmd still aborts compilation. In this
regard discussed issue is clear because there is no doubt whether use case is a
bug or not.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list