Bug 18549 – name gets overwritten in template definition

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
All
Creation time
2018-03-02T21:38:54Z
Last change time
2018-03-11T18:28:02Z
Assigned to
No Owner
Creator
Johannes Nordhoff

Comments

Comment #0 by mephisto — 2018-03-02T21:38:54Z
$ dmd --version DMD64 D Compiler v2.078.2 $ cat app.d ------ struct SS {} struct tt {} void tmpl( SS)() {} void tmpl( tt)() {} void main() { tmpl!SS(); tmpl!tt(); } ------ $ dmd app.d ------ sth.d(11): Error: sth.tmpl called with argument types () matches both: sth.d(6): sth.tmpl!(SS).tmpl() and: sth.d(7): sth.tmpl!(SS).tmpl() sth.d(12): Error: sth.tmpl called with argument types () matches both: sth.d(6): sth.tmpl!(tt).tmpl() and: sth.d(7): sth.tmpl!(tt).tmpl() ------ although I figured out I can fix it by defining the templates like `void tmpl( T : SS)() {}`, the compiler was using the same name for multiple template-definitions. Something must be wrong, I think
Comment #1 by ag0aep6g — 2018-03-04T16:59:02Z
(In reply to Johannes Nordhoff from comment #0) > struct SS {} > struct tt {} > > void tmpl( SS)() {} > void tmpl( tt)() {} The template parameters SS and tt have no relation to the structs of the same name. You could write it like this with the exact same meaning: ---- struct SS {} struct tt {} void tmpl(Foo)() {} void tmpl(Bar)() {} ---- You've got two identical templates with the same name "tmpl". Any attempt at instantiating tmpl will match both (or neither). The error messages you get look fine to me. I'm closing as INVALID, because it looks like you misunderstood how the template parameter names relate to the struct names. [...] > the compiler was using the same name for multiple > template-definitions. I don't understand what you mean by this. If you still think the compiler should do something differently here, please feel free to reopen.
Comment #2 by mephisto — 2018-03-11T18:21:18Z
> > the compiler was using the same name for multiple > > template-definitions. > > I don't understand what you mean by this. If you still think the compiler should do something differently here, please feel free to reopen. > yeah, the error message should say: ---- sth.d(11): Error: sth.tmpl called with argument types () matches both: sth.d(6): sth.tmpl!(SS).tmpl() and: sth.d(7): sth.tmpl!(tt).tmpl() ---- but instead it says: ---- sth.d(11): Error: sth.tmpl called with argument types () matches both: sth.d(6): sth.tmpl!(SS).tmpl() and: sth.d(7): sth.tmpl!(SS).tmpl() ----
Comment #3 by mephisto — 2018-03-11T18:28:02Z
ah, sorry, i get it. sorry