This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Incorrect name lookup in templates.
- To: gcc-bugs at gcc dot gnu dot org
- Subject: Incorrect name lookup in templates.
- From: Hyman Rosen <hymie at prolifics dot com>
- Date: Wed, 2 Feb 2000 19:44:02 -0500
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();
}