This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Incorrect name lookup in templates.


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();
}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]