This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/58878] New: Template parameter name can be hidden in a template member function defined inside the class specifier
- From: "roger.ferrer at bsc dot es" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 25 Oct 2013 13:28:11 +0000
- Subject: [Bug c++/58878] New: Template parameter name can be hidden in a template member function defined inside the class specifier
- Auto-submitted: auto-generated
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,