The following code compiles, but produces an incorrect result. I think this is because g++ seems to incorrectly determine which templated struct foo should be used (the one at the namespace level versus the member struct in bar). The two lines in main() should produce the same result I think, but do not in practice.
The code should, when executed, produce "2\n2\n" I think, but it produces "1\n2\n", showing an incorrect resolving of foo<double> in the first line of main(). Reproducable using 3.3 and 4.0 on OS X as well. Test case code: #include <iostream> struct bar { typedef bar type; template <typename A> struct foo { static const int value = 2; }; }; template <typename B> struct foo : bar { static const int value = 1; }; int main() { // foo<int> is the foo struct at namespace level, foo<double> should be the foo struct within bar, but it is not in g++ std::cout << foo<int>::foo<double>::value << std::endl; // foo<int> is again the foo struct at namespace level, ::type explicitly takes its superclass so foo<double> is the foo struct within bar. std::cout << foo<int>::type::foo<double>::value << std::endl; } -- Summary: g++ incorrectly resolves an identically named templated struct in a super class Product: gcc Version: 4.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: matthijs at bomhoff dot nl GCC target triplet: i486-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33041