[Issue 17541] Function attribute deduction depends on compile invocation
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Feb 17 21:14:00 UTC 2023
https://issues.dlang.org/show_bug.cgi?id=17541
Paul Backus <snarwin+bugzilla at gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |snarwin+bugzilla at gmail.com
--- Comment #13 from Paul Backus <snarwin+bugzilla at gmail.com> ---
Another example, from Discord:
--- test.d
module test;
void main(){
import test2;
MyStruct.RcPtr gl_indcies = MyStruct.RcPtr(MyStruct());
}
--- test2.d
module test2;
struct MyStruct{
alias Ptr = Unique!MyStruct;
alias RcPtr = SafeRefCounted!MyStruct;
~this(){}
}
struct SafeRefCounted(T){
struct RefCountedStore{
struct Impl{
T _payload;
}
Impl* _store;
}
RefCountedStore* _refCounted;
this(T)(T arg){}
~this(){
destroy(_refCounted._store._payload);
}
}
struct Unique(T){
alias RefT = T*;
void opAssign(U)(Unique!U u) if (is(u.RefT:RefT)){}
~this(){
destroy(*_p);
}
RefT _p;
}
---
When compiled together, there is no error:
---
$ dmd -c test.d test2.d && dmd test.o test2.o
$ echo $?
0
---
When compiled separately, linking fails:
---
$ dmd -c test.d && dmd -c test2.d && dmd test.o test2.o
/usr/bin/ld: test.o: in function `_Dmain':
test.d:(.text._Dmain[_Dmain]+0x2f): undefined reference to
`_D5test2__T14SafeRefCountedTSQBb8MyStructZQBf6__dtorMFZv'
collect2: error: ld returned 1 exit status
Error: linker exited with status 1
---
Examining the object files shows that this is due to mismatched attributes:
---
$ nm test.o | ddemangle | grep 'SafeRefCounted.*__dtor'
U void
test2.SafeRefCounted!(test2.MyStruct).SafeRefCounted.__dtor()
$ nm test2.o | ddemangle | grep 'SafeRefCounted.*__dtor'
0000000000000000 W pure nothrow @nogc @safe void
test2.SafeRefCounted!(test2.MyStruct).SafeRefCounted.__dtor()
---
Reproduced with DMD 2.102.0 on 64-bit Linux.
--
More information about the Digitalmars-d-bugs
mailing list