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]

Re: Template instaciation bugs for member function in g++-2.8.1 ?


The following message is a courtesy copy of an article
that has been posted to gnu.g++.help as well.

Yves Dufournaud <Yves.Dufournaud@-o-inrialpes.fr> writes:

> Assumes that we have got
> class A
> {
> public:
>   template<int i>
>   void f() {};
> };

> main()
> {
>  A a;
>  a.f<0>();
> }

> First question is this a valid c++ construction ?
> According to last stroustrup book I think it should be, and if the f()
> function was not a member funtion, it is.

Yes, because the type of `a' is not template-dependent.  If it were,
you'd have to type `a.template f<0>()', otherwise `f' would not be
considered a template-id and the expression would be parsed like this:

((a.f) < (0)) > ()

Fortunately, this error can be fixed by using the `template' keyword,
just like I wrote before.  This error is still occurs in the latest
development snapshots of both gcc and egcs, so I'm CC'ing this message 
there.

> But nevertheless, g++-2.8.1 cannot compile this code (it can if f() is
> not
> a member function), and complains about :
> testTemplate.cc:11: warning: assuming & on `template <int const i>
> A::f()'
> testTemplate.cc:11: warning: assuming pointer to member function is
> non-virtual
> testTemplate.cc:11: invalid operands `void (A::)()' and `int' to binary
> `operator <'
> testTemplate.cc:11: parse error before `('

> If I write (the non member function case):

> template<int i>
> void f() {};

> main()
> {
> f<0>();
> }

> It compile and works.

> So, is the member construct eronous or is this a g++ bug ?

> Any help is welcome,
> Regards,

> Yves.
> --
> Yves Dufournaud  Email Yves.Dufournaud@imag.fr equipe MOVI laboratoire
> GRAVIR
> --
> "Cela n'a rien de remarquable. Il suffit d'appuyer sur la bonne touche
> au
> bon moment et l'instrument joue tout seul" - J.S.Bach

-- 
Alexandre Oliva
mailto:oliva@dcc.unicamp.br mailto:aoliva@acm.org
http://www.dcc.unicamp.br/~oliva
Universidade Estadual de Campinas, SP, Brasil



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