Incorrect name lookup in templates.
Hyman Rosen
hymie@prolifics.com
Wed Feb 2 16:44:00 GMT 2000
Using g++ 2.95.2, the following code compiles and runs, producing
'1:B 2:B 3:B 4:B '. If the 'using B::test' line in main is removed,
the program compiles and produces '1:A 2:A 3:A 4:A '. Neither of
these results is correct. Section 14.6.3 of the C++ Standard states
that non-dependent names (such as test in f<N>::t) are looked up at
the point where they are used. In this case, test is ambiguous, so
the code should not compile at all.
#include <iostream>
namespace A { void test(int n) { std::cout << n << ":A "; } }
namespace B { void test(int n) { std::cout << n << ":B "; } }
template <int N> struct f { void t() { test(N); } };
f<1> f1;
using namespace A;
f<2> f2;
int main()
{
f<3> f3;
using B::test;
f<4> f4;
f1.t(); f2.t(); f3.t(); f4.t();
}
More information about the Gcc-bugs
mailing list