[Bug c++/53573] template type dependent name resolution broken

keean@fry-it.com gcc-bugzilla@gcc.gnu.org
Tue Jun 5 09:06:00 GMT 2012


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53573

--- Comment #6 from Keean Schupke <keean@fry-it.com> 2012-06-05 09:06:01 UTC ---
The suggested work around in the error message 'adding -fpermissive' to
gcc-4.7.0 does not fix the problem as suggested by the error message. This
would suggest the compiler is not displaying the correct error message for the
problem.

g++ -fpermissive test.cpp

Still generates:

test.cpp: In instantiation of ‘T f(T) [with T = int]’:
test.cpp:27:9:   required from here
test.cpp:18:12: error: ‘g’ was not declared in this scope, and no declarations
were found by argument-dependent lookup at the point of instantiation
[-fpermissive]
test.cpp:21:5: note: ‘int g(int)’ declared here, later in the translation unit


A further test:



int g(int x) {
    return x + 1;
}

char g(char x) {
    return x - 1;
}

template <typename T> T f(T t) {
    return g((T)t);
}

double g(double x) {
    return x;
}

main() {
    double x(f(1.0L));
}



generates the following compile time error:


test.cpp: In instantiation of ‘T f(T) [with T = long double]’:
test.cpp:18:17:   required from here
test.cpp:10:15: error: call of overloaded ‘g(long double)’ is ambiguous
test.cpp:10:15: note: candidates are:
test.cpp:1:5: note: int g(int)
test.cpp:5:6: note: char g(char)



Which is interesting as it suggests that the overloading of 'g' is happening
from the definitions of 'g' that are in scope at the template definition. This
is quite strange behaviour, as the compiler must have to capture a list all
available overloads at the time of definition of each template. This looks like
a deliberate behaviour rather than a bug.

So this looks more like a misunderstanding of the specification is the cause of
this incorrect behaviour?



More information about the Gcc-bugs mailing list