Thread overview
[Issue 4027] New: Nested function's bug in CTFE
Mar 29, 2010
SHOO
[Issue 4027] Closures in CTFE generate wrong code
Mar 30, 2010
Don
Apr 01, 2010
Walter Bright
Apr 10, 2010
Don
March 29, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4027

           Summary: Nested function's bug in CTFE
           Product: D
           Version: 2.041
          Platform: x86
               URL: http://dusers.dip.jp/modules/forum/index.php?topic_id=
                    59#post_id222
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: zan77137@nifty.com


--- Comment #0 from SHOO <zan77137@nifty.com> 2010-03-29 14:19:25 PDT ---
(This bug was posted to the Japanese community site. I translate this report.)

This code doesn't work!
-------------------------------------------
auto f(string s)
{
    return { return s; };
}
void main()
{
    static immutable s = f("aaa")();
    static assert(s == "aaa");// Error: static assert  (null == "aaa") is false
}
-------------------------------------------



The function fails regardless of the argument when execute the following codes in CTFE:
-------------------------------------------
auto f(string s)
{
    return { assert(s); };
}
-------------------------------------------



You can take the following measures to avoid this problem:
-------------------------------------------
auto f(string s)
{
    auto _s = s;
    return { assert(_s); };
}
-------------------------------------------

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 30, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4027


Don <clugdbug@yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-code
                 CC|                            |clugdbug@yahoo.com.au
            Summary|Nested function's bug in    |Closures in CTFE generate
                   |CTFE                        |wrong code


--- Comment #1 from Don <clugdbug@yahoo.com.au> 2010-03-30 11:42:35 PDT ---
The workaround does NOT work. It only looks as though it does. See this, for
example:
===
string delegate() bug4027(string s1) {
  string s = s1;
  return { return s; };
}

int food() {
 auto a = bug4027("aaa");
 auto b = bug4027("bbb");
 assert(a() == "aaa");  // fails -- a() is "bbb" !!!
 return 1;
}

static assert(food()==1);
----
The root cause is that closures are not yet supported in CTFE. They should generate an error message at compile time.

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


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla@digitalmars.com


--- Comment #2 from Walter Bright <bugzilla@digitalmars.com> 2010-04-01 13:54:35 PDT ---
changeset 429

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 10, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4027


Don <clugdbug@yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


--- Comment #3 from Don <clugdbug@yahoo.com.au> 2010-04-09 19:21:30 PDT ---
Fixed DMD2.043.

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