https://issues.dlang.org/show_bug.cgi?id=6744

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

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

--- Comment #10 from Kenji Hara <k.hara...@gmail.com> ---
(In reply to Kenji Hara from comment #2)
> This is not only the problem of AA, it is where template instantiation is
> belongs to.
> 
> ---- test.d
> import traits;
> void func()(){ X!() x; auto n = x.length; }
> void main(){ func(); assert(0); }
> 
> ---- traits.d
> struct X(){ int length(){ return 0; } }
> enum x = X!()();
> 
> ---- command line
> dmd test.d
> 
> ---- output
> OPTLINK (R) for Win32  Release 8.00.7
> Copyright (C) Digital Mars 1989-2010  All rights reserved.
> http://www.digitalmars.com/ctg/optlink.html
> test2.obj(test2)
>  Error 42: Symbol Undefined _D6traits6__T1XZ1X6lengthMFZi
> 
> semantic() runs against the type of X!() at both line 2 in test and line 2
> of traits, but its instantiation belongs to only traits, because the
> semantic runs  first in traits.
> But the module traits never generate .obj, then the symbol ob X!().length
> will be lost.


Now, the question has been resolved.

Since 2.064, new template instantiation strategy has been introduced:

https://github.com/D-Programming-Language/dmd/pull/2550

By that, when a template X!() is instantiated in both root module (test.d) and
non-root module (traits.d), it's assumed that the instantiated code would exist
in the linked object file of the non-root module.
But the command line `dmd test.d` does not correctly compile & link the
traits.d module.
Then test.obj fail to link the instantiated X!().length() funciton.
In short, the link-failure is intentional behavior.

Close this issue as "resolved".

--

Reply via email to