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: nob...@puremagic.com
        ReportedBy: c...@klickverbot.at


--- Comment #0 from klickverbot <c...@klickverbot.at> 2012-10-06 12:09:43 PDT 
---
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 algorithm.o file.o # Works fine

# Now recompile algorithm.
dmd -c algorithm.d

# ... and try to link again:
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_D4file10dirEntries1fMFZvTS4file11DirIteratorZ12FilterResult'
 

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: -------

Reply via email to