Bug 6072 – [CTFE] Regression(git master): Cannot declare variable inside an 'if' condition

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Mac OS X
Creation time
2011-05-29T03:36:00Z
Last change time
2011-05-31T19:15:18Z
Keywords
rejects-valid
Assigned to
nobody
Creator
kennytm

Comments

Comment #0 by kennytm — 2011-05-29T03:36:37Z
Test case: --------------- static assert({ if (int x = 5) {} return true; }()); void main(){} --------------- x.d(4): Error: cannot evaluate delegate bool() { if (int x = int x = 5; , x) { } return true; } () at compile time x.d(1): Error: static assert (delegate bool() { if (int x = int x = 5; , x) { } return true; } ()) is not evaluatable at compile time --------------- This bug was introduced in commit 269a344 as a fix to bug 3688. The direct consequence is std.traits.functionAttributes is no longer usable. ------------------ import std.traits; struct S { pure int f(); } enum g = functionAttributes!(S.f); ------------------ /usr/include/phobos/std/traits.d(363): Error: cannot evaluate demangleFunctionAttributes("NaZi"c) at compile time ------------------
Comment #1 by kennytm — 2011-05-29T07:32:54Z
To workaround this fors std.traits.functionAttributes: diff --git a/std/traits.d b/std/traits.d index 47ee059..67f14ad 100644 --- a/std/traits.d +++ b/std/traits.d @@ -89,7 +89,8 @@ private // FuncAttr --> empty | Na | Nb | Nc | Nd | Ne | Nf while (mstr.length >= 2 && mstr[0] == 'N') { - if (FunctionAttribute att = LOOKUP_ATTRIBUTE[ mstr[1] ]) + FunctionAttribute att = LOOKUP_ATTRIBUTE[ mstr[1] ]; + if (att) { atts |= att; mstr = mstr[2 .. $];
Comment #2 by bugzilla — 2011-05-31T19:15:18Z