Thread overview | |||||
---|---|---|---|---|---|
|
June 06, 2010 [Issue 4284] New: empty string[] alias lacks .length in a template | ||||
---|---|---|---|---|
| ||||
http://d.puremagic.com/issues/show_bug.cgi?id=4284 Summary: empty string[] alias lacks .length in a template Product: D Version: future Platform: x86 OS/Version: Windows Status: NEW Severity: normal Priority: P2 Component: DMD AssignedTo: nobody@puremagic.com ReportedBy: bearophile_hugs@eml.cc --- Comment #0 from bearophile_hugs@eml.cc 2010-06-06 06:43:17 PDT --- This looks like a correct D2 program: import std.string: split; template Foo(alias items) { static if (items.length == 0) enum Foo = 1; else enum Foo = 2; } enum string[] items = split(""); static assert(Foo!(items) == 1); void main() {} But DMD v2.046 prints at compile-time: test.d(3): Error: expression (null.length) == 0u is not constant or does not evaluate to a bool test.d(9): Error: template instance test.Foo!(items) error instantiating test.d(9): Error: static assert (2 == 1) is false ------------------------ To fix it you have to test for null too: import std.string: split; template Foo(alias items) { static if (items == null || items.length == 0) enum Foo = 1; else enum Foo = 2; } enum string[] items = split(""); static assert(Foo!(items) == 1); void main() {} -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
September 06, 2011 [Issue 4284] empty string[] alias lacks .length in a template | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile_hugs@eml.cc | http://d.puremagic.com/issues/show_bug.cgi?id=4284 yebblies <yebblies@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |patch, rejects-valid CC| |yebblies@gmail.com Platform|x86 |All OS/Version|Windows |All --- Comment #1 from yebblies <yebblies@gmail.com> 2011-09-06 14:47:59 EST --- https://github.com/D-Programming-Language/dmd/pull/365 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
September 18, 2011 [Issue 4284] empty string[] alias lacks .length in a template | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile_hugs@eml.cc | http://d.puremagic.com/issues/show_bug.cgi?id=4284 Walter Bright <bugzilla@digitalmars.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED CC| |bugzilla@digitalmars.com Resolution| |FIXED --- Comment #2 from Walter Bright <bugzilla@digitalmars.com> 2011-09-17 17:19:59 PDT --- https://github.com/D-Programming-Language/dmd/commit/4ff28a3be1a35013cb6046b21c43a55f1b87f676 https://github.com/D-Programming-Language/dmd/commit/70174180cbfc83c9cde9d745ca367b08b49af398 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
Copyright © 1999-2021 by the D Language Foundation