Bug 4616 – Link error with copy constructor of nested struct
Status
RESOLVED
Resolution
WORKSFORME
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
All
Creation time
2010-08-10T21:42:00Z
Last change time
2015-03-03T13:37:57Z
Keywords
link-failure
Assigned to
nobody
Creator
rsinfu
Comments
Comment #0 by rsinfu — 2010-08-10T21:42:57Z
If a struct N is nested inside another struct S and N has a field of type S, then defining a copy constructor of N causes a linker error.
The error occurs only when N has a field of type S.
-------------------- test.d
struct S
{
struct N
{
S s;
this(this) {} // error
}
}
--------------------
The error on FreeBSD:
--------------------
% dmd test.d
test.o(.text._D4test1S1N8__cpctorMFKS4test1S1NZv+0x18): In function `_D4test1S1N8__cpctorMFKS4test1S1NZv':
: multiple definition of `_D4test1S1N8__cpctorMFKS4test1S1NZv'
test.o(.text._D4test1S1N8__cpctorMFKS4test1S1NZv+0x0): first defined here
--------------------
The error on Windows:
--------------------
>dmd test.d
OPTLINK (R) for Win32 Release 8.00.2
Copyright (C) Digital Mars 1989-2009 All rights reserved.
http://www.digitalmars.com/ctg/optlink.html
test.obj(test) Offset 00403H Record Type 00C3
Error 1: Previous Definition Different : _D4test1S1N8__cpctorMFKS4test1S1NZv
--------------------
Comment #1 by ds.dlang — 2012-12-17T01:45:51Z
This no longer seems to be reproducible. With dmd compiled from the current head, the following code (a bit more involved to test it better) compiles and works (on MacOSX):
import std.stdio;
struct S {
struct N {
S s;
this(this) { s.value += 1; }
}
int value = 17;
}
int main() {
S.N n1;
S.N n2 = n1;
writefln("%d %d", n1.s.value, n2.s.value);
return 0;
}
Prints "17 18".