This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Local types and template template members


The following program fails to compile with either gcc-2.95.3 (Linux
Mandrake 7.2, Intel ) or gcc-2.95.2 (Linux Mandrake 7.2 and Windows
2000)  :

#include <iostream>

template <typename T = double>
class A
{
public:
    template <typename U>
    T f(U u)
    {
       struct Local {};
       return u;
    }
};

main()
{
    A<> a;
    cout << a.f(3) << endl;
    return 0;
}

Here is the compiler output (identical with both versions of gcc) :

g++ def_templ.cc
def_templ.cc: In method `T A<T>::f(U)':
def_templ.cc:10: default argument for template parameter for class
enclosing `A<T>::f(U)::Local'
def_templ.cc: In function `int main()':
def_templ.cc:17: wrong number of template arguments (0, should be 1)
def_templ.cc:5: provided for `template <class T> A<T>'
def_templ.cc:17: ANSI C++ forbids declaration `a' with no type
def_templ.cc:18: request for member `f' in `a', which is of
non-aggregate type `int'

What bothers me is the first error, of course. If one removes the
default template parameter, or the local type Local, everything works
fine, as it should IMHO. This is not forbidden by the standard, is it? I
could not see where (and why). This may have been a misinterpretation of
some (obscure) standard sentences, as it may be demonstrated by the
follwing experiment. If one externalizes the definition of the template
template member, everything works fine again :

#include <iostream>

template <typename T = double>
class A
{
public:
    template <typename U>
    T f(U u);
};

template <typename T>
template <class U>
T A<T>::f(U u)
{
    struct Local {};
    return u;
}

main()
{
    A<> a;
    cout << a.f(3) << endl;
    return 0;
}

whereas if I just redefine the default  template parameter in  the
definition of the member f '(which *is* explicitely forbidden by the
standard)

template <typename T = double>
template <class U>
T A<T>::f(U u)
{
//    struct Local {};
    return u;
}

I get the same message again, even if there is no local type (which is
OK, standard-wise).

Thanks for any help

        Jean-Paul Rigault



begin:vcard 
n:Rigault;Jean-Paul
tel;cell:+33 6 80 40 89 62
tel;fax:+33 4 92 19 12 19
tel;home:+33 4 92 19 12 19
tel;work:+33 4 92 96 51 33
x-mozilla-html:TRUE
url:http://www.essi.fr/
org:University of Nice Sophia Antipolis;ESSI
version:2.1
email;internet:jpr@essi.fr
title:Professor
adr;quoted-printable:;;BP 145=0D=0A930 route des Colles;Sophia Antipolis Cedex;;06903;France
fn:Jean-Paul Rigault
end:vcard

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]