Thread overview
[Issue 9101] New: template mixin constructor causes link error
Dec 01, 2012
Rainer Schuetze
Dec 01, 2012
Rainer Schuetze
Dec 05, 2012
Kenji Hara
Dec 05, 2012
Rainer Schuetze
Dec 12, 2012
Kenji Hara
Dec 12, 2012
Kenji Hara
Dec 12, 2012
Walter Bright
December 01, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=9101

           Summary: template mixin constructor causes link error
           Product: D
           Version: D2
          Platform: All
        OS/Version: Windows
            Status: NEW
          Severity: regression
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: r.sagitario@gmx.de


--- Comment #0 from Rainer Schuetze <r.sagitario@gmx.de> 2012-12-01 03:25:00 PST ---
With latest dmd from github, this code produces a link error:

class Node
{
    int id;

    this()
    {
    }

    this(int tok)
    {
        id = tok;
    }

    mixin template ForwardCtorNoId()
    {
        this() {} // default constructor needed for clone()

        this(int tok)
        {
            super(tok);
        }
    }
}

class Derived : Node
{
    mixin ForwardCtorNoId!();
}


void main()
{
}

This does not happen with dmd 2.060 and using bisect, it seems to be introduced with this commit: 8bc59cfe8e6896435f20ce1e9bdcc226942f59a8 fix Issue 5893 - Allow simple aliases for operator overloading

A work around seems to be to move the mixin declaration out of the base class scope.

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



--- Comment #1 from Rainer Schuetze <r.sagitario@gmx.de> 2012-12-01 09:53:35 PST ---
Forgot to post the error message:

>dmd.exe test.d
OPTLINK (R) for Win32  Release 8.00.11
Copyright (C) Digital Mars 1989-2010  All rights reserved.
http://www.digitalmars.com/ctg/optlink.html
test.obj(test)
 Error 42: Symbol Undefined
_D4test4Node21__T15ForwardCtorNoIdZ6__ctorMFZC4test4
Node
--- errorlevel 1

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
December 05, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=9101



--- Comment #2 from Kenji Hara <k.hara.pg@gmail.com> 2012-12-04 19:25:58 PST ---
(In reply to comment #0)
> This does not happen with dmd 2.060 and using bisect, it seems to be introduced with this commit: 8bc59cfe8e6896435f20ce1e9bdcc226942f59a8 fix Issue 5893 - Allow simple aliases for operator overloading
> 
> A work around seems to be to move the mixin declaration out of the base class scope.

Both newest git head (2f50520) and the trunk commit which merged pull #980
(2888ec4) doesn't occur such link error in Windows.

But, in current I use optlink 8.00.5

  > link
  OPTLINK (R) for Win32  Release 8.00.5
  Copyright (C) Digital Mars 1989-2009  All rights reserved.
  http://www.digitalmars.com/ctg/optlink.html

Might this be a optkink bug?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
December 05, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=9101



--- Comment #3 from Rainer Schuetze <r.sagitario@gmx.de> 2012-12-05 00:14:58 PST ---
It's not the linker, the symbol is referenced from within the object file.

The problem is triggered by my precise GC patches in druntime where generation of RTInfo needs to iterate over the members of the class. The bad operation boils down to

static if (__traits(compiles, Node.ForwardCtorNoId.offset+1)) {}

When added to the test case, the error appears with the standard druntime, too. The derived class is not needed then.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
December 12, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=9101



--- Comment #4 from Kenji Hara <k.hara.pg@gmail.com> 2012-12-12 00:07:53 PST ---
(In reply to comment #3)
> It's not the linker, the symbol is referenced from within the object file.
> 
> The problem is triggered by my precise GC patches in druntime where generation of RTInfo needs to iterate over the members of the class. The bad operation boils down to
> 
> static if (__traits(compiles, Node.ForwardCtorNoId.offset+1)) {}
> 
> When added to the test case, the error appears with the standard druntime, too. The derived class is not needed then.

OK, the original case has been broken by fixing issue 5893 certainly.

But following shrinked code causes same linker error, and it has been caused same linker error from before fixing 5893.
----
class Node
{
    template ForwardCtorNoId()
    {
        this() {} // default constructor
        void foo() { 0 = 1; }    // wrong code
    }
}
enum x = __traits(compiles, Node.ForwardCtorNoId!());
void main() {}
----

Therefore, the root cause was not a regression.
But your code actually be broken in 2.061head. So I'd like to keep this issue
marked as regression. Thanks.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
December 12, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=9101


Kenji Hara <k.hara.pg@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |link-failure, pull


--- Comment #5 from Kenji Hara <k.hara.pg@gmail.com> 2012-12-12 00:28:36 PST ---
https://github.com/D-Programming-Language/dmd/pull/1367

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
December 12, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=9101



--- Comment #6 from github-bugzilla@puremagic.com 2012-12-12 02:56:08 PST ---
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/9e36de3edaabe74c7f81f1ebe563ecd8186c960c fix Issue 9101 - template mixin constructor causes link error

https://github.com/D-Programming-Language/dmd/commit/c4dc64092ae2ae8d774ae5d9b2af5b440dfff40f Merge pull request #1367 from 9rnsr/fix9101

Issue 9101 - template mixin constructor causes link error

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
December 12, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=9101


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla@digitalmars.com
         Resolution|                            |FIXED


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