D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 9101 - template mixin constructor causes link error
Summary: template mixin constructor causes link error
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All Windows
: P2 regression
Assignee: No Owner
URL:
Keywords: link-failure, pull
Depends on:
Blocks:
 
Reported: 2012-12-01 03:25 UTC by Rainer Schuetze
Modified: 2012-12-12 12:55 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Rainer Schuetze 2012-12-01 03:25:00 UTC
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.
Comment 1 Rainer Schuetze 2012-12-01 09:53:35 UTC
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
Comment 2 Kenji Hara 2012-12-04 19:25:58 UTC
(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?
Comment 3 Rainer Schuetze 2012-12-05 00:14:58 UTC
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.
Comment 4 Kenji Hara 2012-12-12 00:07:53 UTC
(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.
Comment 6 github-bugzilla 2012-12-12 02:56:08 UTC
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