Thread overview
[Issue 6072] New: [CTFE] Regression(git master): Cannot declare variable inside an 'if' condition
May 29, 2011
kennytm@gmail.com
May 29, 2011
kennytm@gmail.com
Jun 01, 2011
Walter Bright
May 29, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6072

           Summary: [CTFE] Regression(git master): Cannot declare variable
                    inside an 'if' condition
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Mac OS X
            Status: NEW
          Keywords: rejects-valid
          Severity: regression
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: kennytm@gmail.com


--- Comment #0 from kennytm@gmail.com 2011-05-29 03:36:37 PDT ---
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
------------------

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 29, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6072



--- Comment #1 from kennytm@gmail.com 2011-05-29 07:32:54 PDT ---
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 .. $];

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 01, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6072


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-05-31 19:15:18 PDT ---
https://github.com/D-Programming-Language/dmd/commit/e921b529a022fda0e01153464fc0f91e83647ba5

https://github.com/D-Programming-Language/dmd/commit/e122d4ade8ebf7d117825494598e047369ebbe48

https://github.com/D-Programming-Language/dmd/commit/f84fb58a03456996cc579253901acce5b72a5138

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