http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58878
Bug ID: 58878 Summary: Template parameter name can be hidden in a template member function defined inside the class specifier Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: roger.ferrer at bsc dot es Hi, g++ allows declarations to hide a template-parameter name in template member functions defined inside the class-specifier. I have not been able to find whether this was expected behaviour in g++ so I'm inclined to believe this is an error in g++. Following is a testcase where several declarations attempt to hide template-parameter names 't' and 's' in the scope. g++ accepts cases 1, 5 and 6 and (I think) it should not allow them. The remaining cases seem to be correctly diagnosed. This fails both in g++ 4.8.1 and g++ 4.9.0 20131015 (experimental). -- test.c // Template-members of non-template class struct A { template <typename t> void f() { int t = 1; // Error. g++ does NOT complain } template <typename t> void g(); }; template <typename t> void A::g() { int t = 2; // OK. g++ DOES complain } // (Non-template) Members of template class template <typename t> struct B { void f() { int t = 3; // OK. g++ DOES complain } void g(); }; template <typename t> void B<t>::g() { int t = 4; // OK. g++ DOES complain } // Template members of template class template <typename t> struct C { template <typename s> void f() { int t = 5; // Error. g++ does NOT complain int s = 6; // Error. g++ does NOT complain } template <typename s> void g(); }; template <typename t> template <typename s> void C<t>::g() { int t = 7; // OK. g++ DOES complain int s = 8; // OK. g++ DOES complain } -- end of test.cc $ g++ -c test.cc test.cc: In member function ‘void A::g()’: test.cc:17:9: error: declaration of ‘int t’ int t = 2; // OK. g++ DOES complain ^ test.cc:14:11: error: shadows template parm ‘class t’ template <typename t> ^ test.cc: In member function ‘void B<t>::f()’: test.cc:26:13: error: declaration of ‘int t’ int t = 3; // OK. g++ DOES complain ^ test.cc:21:11: error: shadows template parm ‘class t’ template <typename t> ^ test.cc: In member function ‘void B<t>::g()’: test.cc:35:9: error: declaration of ‘int t’ int t = 4; // OK. g++ DOES complain ^ test.cc:32:11: error: shadows template parm ‘class t’ template <typename t> ^ test.cc: In member function ‘void C<t>::g()’: test.cc:58:9: error: declaration of ‘int t’ int t = 7; // OK. g++ DOES complain ^ test.cc:54:11: error: shadows template parm ‘class t’ template <typename t> ^ test.cc:59:9: error: declaration of ‘int s’ int s = 8; // OK. g++ DOES complain ^ test.cc:55:11: error: shadows template parm ‘class s’ template <typename s> I'd expect error messages for 1, 5 and 6 to appear as well. Kind regards,