Bug 2268 – Hijacking of non-templated functions by templated functions should not be allowed.
Status
RESOLVED
Resolution
FIXED
Severity
critical
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2008-08-06T12:26:00Z
Last change time
2015-06-09T01:19:59Z
Keywords
diagnostic
Assigned to
bugzilla
Creator
dsimcha
Comments
Comment #0 by dsimcha — 2008-08-06T12:26:18Z
It appears that the compiler does not properly handle collisions between function names in different modules when one of the functions is a template.
Case 1: Find is not templated in either std.string or std.regexp, compilation fails with a conflicts error message.
import std.string, std.regexp;
void main() {
int i = find("foobar", "foo");
}
Case 2: Find is templated in std.algorithm, compiler silently tries to instantiate std.algorithm.find, instantiation fails with error specific to std.algorithm.find implementation.
import std.string, std.algorithm;
void main() {
int i = find("foobar", "foo");
}
I've marked this bug as major because, if a user runs into it and is not aware of it, it can be extremely difficult to figure out why the program doesn't compile.
Comment #1 by dsimcha — 2008-09-04T14:56:37Z
Added much more descriptive title, now that I'm more familiar with the general issue here.
Comment #2 by dsimcha — 2009-01-25T22:11:24Z
Upgrading to critical and incrementing version because this bug still exists, I've been bitten by this several times now, and each time it's quite confusing. Also, the following example actually does give a proper error message, because instantiation of std.algorithm.find succeeds, and then DMD realizes that it conflicts with std.string.find:
import std.algorithm, std.string;
void main() {
auto i = find("foobar", 'f');
}
The root of the problem, then, is that DMD tries to instantiate any template functions that match the name of the function being called before outputting a name conflict error message. If the instantiation of these templates fails, then DMD fails with error messages related to its attempt at instantiating the template, rather than either silently using the non-template function (probably a bad idea) or failing with a name conflict error message (the right thing). Instead, DMD should fail *before* trying to instantiate the template function whose name conflicts with the non-template function, if they are not in the same overload set.
Comment #3 by smjg — 2009-01-30T20:44:06Z
The rule around here is that the version field should be set to the _oldest_ version in which the bug has been observed.
http://tinyurl.com/avzytb
Comment #4 by dsimcha — 2009-05-13T09:29:01Z
Works in 2.030, but see bug 2972. I think the fix caused this bug.