www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 20766] New: empty string literals passed as optional


          Issue ID: 20766
           Summary: empty string literals passed as optional parameter
                    should not be 0 terminated
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: b2.temp gmx.com

concrete illustration:

void main()

void test(string s = "")
    if (s) {}
    else   { assert(false); }
    s ? {} : assert(false);

`""` is actually a pointer to 0x00 and a length of 0.  Since `s.ptr` will never
be null the else branch (or the last exp of a CondExpr) will never be executed,
even when calling test() without argument.

Apr 25 2020