digitalmars.D.bugs - [Issue 20766] New: empty string literals passed as optional
- d-bugmail puremagic.com (31/31) Apr 25 2020 https://issues.dlang.org/show_bug.cgi?id=20766
https://issues.dlang.org/show_bug.cgi?id=20766 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() { test(); } 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