www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 8769] New: Template instantiation emitted into wrong file on multi-obj compilation

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8769

           Summary: Template instantiation emitted into wrong file on
                    multi-obj compilation
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: code klickverbot.at



---
Consider the following test case:

---
// algorithm.d
auto filter(alias pred, Range)(Range rs) {                                      
    return FilterResult!(pred, Range)(rs);                                      
}                                                                               

struct FilterResult(alias pred, Range) {                                        
    this(Range r) {}
}

---
---
// file.d
import algorithm;

struct DirIterator {}

auto dirEntries() {
    void f() {}
    return filter!f(DirIterator());
}

void main() {}
---

---
dmd -c algorithm.d file.d



dmd -c algorithm.d


dmd algorithm.o file.o
---

The second attempt to link fails with

file.d:(.text._D4file10dirEntriesFZS4file10dirEntries66__T12FilterResultS25_D4file10dirEntries1fMFZvTS4file11DirIteratorZ12FilterResult59__T6filterS25_D4file10dirEntries1fMFZvTS4file11DirIteratorZ6filterMFS4file11DirIteratorZS4file10dirEntries66__T12FilterResultS25_D4file10dirEntries1fMFZvTS4file11DirIteratorZ12FilterResult+0x1e):
undefined reference to
`_D4file10dirEntriesFZS4file10dirEntries66__T12FilterResultS25_D4file10dirEntries1fMFZvTS4file11DirIteratorZ12FilterResult66__T12FilterResultS25_D4file10dirEntries1fMFZvTS4file11DirIteratorZ12FilterResult6__ctorMFS4file11DirIteratorZS4file10dirEntries66__T12FilterResultS25_D4file10dirEntries1fMFZvTS4file11DirIter
torZ12FilterResult' 

because DMD initially emitted the symbol in question to algorithm.o instead of
file.o.

I'm not quite sure about an easy way to fix this. The simple heuristic in
https://github.com/D-Programming-Language/dmd/blob/67681b916f7880432c7da14a714404af0254278e/src/template.c#L4854
unfortunately fails once algorithm.d is present on the command line itself,
because then (<algorithm>.importedFrom == <algorithm>).

We likely need to track the template instantiation "origin" over the whole
chain.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 06 2012
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8769


Martin Nowak <code dawg.eu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |code dawg.eu
         Resolution|                            |DUPLICATE



*** This issue has been marked as a duplicate of issue 3274 ***

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