www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 7419] New: [2.058/CTFE] Constructor of struct is overwritten inside a unittest with -inline

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7419

           Summary: [2.058/CTFE] Constructor of struct is overwritten
                    inside a unittest with -inline
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: CTFE
          Severity: regression
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: kennytm gmail.com



Test case:

-----------------
struct X7419 {
    double x;
    this(double x) {
        this.x = x;
    }
}
unittest {
    enum x = {
        auto p = X7419(3);
        return p.x;
    }();
    static assert(x == 3);
}
-----------------

Compile with:

    dmd -unittest -inline -c test7419.d

Gives the unexpected error:

    test7419.d(12): Error: static assert  (nan == 3) is false

The bug was introduced in commit 40160a53a0c72bfbad2e0ad36ec8f1ccbb76ce8d.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 01 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7419


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clugdbug yahoo.com.au
         AssignedTo|nobody puremagic.com        |clugdbug yahoo.com.au



It doesn't need unittest. The -inline seems to be necessary, I presume it's
creating a ref variable.

struct X7419 {
    double x;
    this(double x) {
        this.x = x;
    }
}

void bug7419() {
    enum x = {
        auto p = X7419(3);
        return p.x;
    }();
    static assert(x == 3);
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 01 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7419


Walter Bright <bugzilla digitalmars.com> changed:

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



21:24:53 PST ---
Linky:
https://github.com/D-Programming-Language/dmd/commit/40160a53a0c72bfbad2e0ad36ec8f1ccbb76ce8d

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 01 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7419




22:00:23 PST ---
Looking at that git commit, if I add back in the following code that was
elided:

3450a3451,3459
 #if 1
 if (op==TOKconstruct && this->e1->op==TOKvar && this->e2->op != TOKthis
         && this->e2->op != TOKcomma
         && ((VarExp*)this->e1)->var->storage_class & STCref)
         wantRef = true;
 #endif
then it works. Note that when -inline is used, the only function that gets inlined is the constructor call. Note the comment for the elision, saying it is to fix something with foreach, yet foreach is not in this example, I think the problem is in CTFE. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 01 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7419





 Looking at that git commit, if I add back in the following code that was
 elided:
 
 3450a3451,3459
 #if 1
 if (op==TOKconstruct && this->e1->op==TOKvar && this->e2->op != TOKthis
         && this->e2->op != TOKcomma
         && ((VarExp*)this->e1)->var->storage_class & STCref)
         wantRef = true;
 #endif
then it works. Note that when -inline is used, the only function that gets inlined is the constructor call. Note the comment for the elision, saying it is to fix something with foreach, yet foreach is not in this example, I think the problem is in CTFE.
That code was introduced as a hack to get ref foreach to work in CTFE, but it isn't correct (the != TOKthis and != TOKcomma is a hack). Later, after fixing some other bugs, ref foreach works without it. I have made a proper fix, which I will post tonight. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 02 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7419




Commit pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/127d0110b839e5bdc2997ae0b586b1e93c7c8daa
7419 [2.058/CTFE] Constructor of struct is overwritten with -inline

The logic for ref variables was incorrect. Stripping out _all_ of the funky
foreach code fixes it.
Fixes bug 7419.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 03 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7419


Walter Bright <bugzilla digitalmars.com> changed:

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



00:59:51 PST ---
Commit pushed to dmd-1.x at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/467cf6687f60dbb4180df036bd0508b9ce408d19
fix issue 6504, fix issue 7419

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