Incorrect name lookup in templates.
Martin v. Loewis
martin@loewis.home.cs.tu-berlin.de
Thu Feb 3 15:58: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.
Thanks for your bug report. This is a known bug; g++ does not bind
non-dependent names correctly unless they are type names.
> #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); } };
One minor correction to your analysis: test is not defined at this
point at all, so this is not an ambiguity - lookup does not find a
single candidate for test (note that test is value-dependent, not
type-dependent).
Regards,
Martin
More information about the Gcc-bugs
mailing list