This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Shadowing in template template function within class template.
- From: "Rodolfo Federico Gamarra" <rgamarra at gmail dot com>
- To: gcc-help at gcc dot gnu dot org
- Date: Thu, 8 Jan 2009 23:59:18 -0200
- Subject: Shadowing in template template function within class template.
- References: <145cab720901070901h1e7e4544g9abcdb94ddb8d965@mail.gmail.com> <145cab720901081757v6596cbaek87efbab67f2f7985@mail.gmail.com>
Hi all!
I have a question about the diagnosis and resolution of template
arguments, in a situation which aborts the compilation. The problem
itself can be bypassed easily.
I'm using g++ (GCC) 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)
I have a template template function in three different contexts:
(I) As a member of a template class.
(II) As a member of class.
(III) As a plain function.
The template argument declaration for it may be
template <class R, template<class S> class T >
if the declaration is changed to
template <class R, template<class R> class T >
then the upon compilation the result is
error: declaration of 'class R'
error: shadows template parm 'class R'
only in case (I).
In can't see the reason why there are different diagnoses depending on
the context (I, II or III). As of item 3 of 14.6.1 ("Locally declared
names") of The Standard hidding is ocurring in all three cases:
"The scope of a template-parameter extends from its of declaration
until the end of its template. A template-parameter hides any entity
with the same name in the enclosing scope."
I have put an example at the end of the email.
Thanks a lot for your help.
--
Rodolfo Federico Gamarra
// Dummy template class.
template<class> class A { };
// Template class with templated member function.
template<class> class B {
public:
/*
template <class R,
template<class R> //--> shadows. Doesn't compile.
class T >
//main.cc:8: error: declaration of 'class R'
//main.cc:7: error: shadows template parm 'class R'
*/
/**/
template <class R,
template<class S>
class T >
/**/
void f(T<R> a) { }
};
// Class with template member function.
class C {
public:
template <class R,
template<class R> // this doesn't shadow. Compiles 0k.
class T >
void f(T<R> a) { }
};
// Function template.
template <class R,
template<class R> // this doesn't shadow. Compiles 0k.
class T>
void f(T<R>& a) { }
int main()
{
A<int> a;
B<int> b;
C c;
b.f(a);
c.f(a);
f(a);
}