This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: member template functions && strange warnings
- To: Alexandre Guimond <guimond at epidaure dot inria dot fr>
- Subject: Re: member template functions && strange warnings
- From: Alexandre Oliva <oliva at dcc dot unicamp dot br>
- Date: 09 Sep 1998 00:07:11 z
- Cc: egcs at cygnus dot com
- References: <35F4F8FD.75FA35F@epidaure.inria.fr>
Alexandre Guimond <guimond@epidaure.inria.fr> writes:
> I'm trying to figure out what causes the warnings in the following
> program and if there is a way to get rid of them. I get the following
> warnings (compile with g++ -Wall throw.c) :
> throw.c:23: warning: declaration of `A<T>::foo(T *)' throws different
> exceptions
> throw.c:16: warning: previous declaration here
egcs 1.1 is wrong, the `throw' declarations are identical.
> throw.c: In function `int main()':
> throw.c:38: warning: passing `F' chooses `int' over `long unsigned int'
> throw.c:38: warning: in call to `ostream::operator <<(int)'
Enumeration types may need underlying types such as unsigned or long
ints, depending on the target host architecture. egcs is just warning
you that this enum was mapped onto an int type, but it *might* have
been mapped onto another type by some other compiler. This is not
right, since this particular enumeration would always fit in an int,
so it *must* be stored in an int. Anyway, egcs warns you that it has
preferred to convert the enum to an `int', rather than to another
larger integral type. You can avoid the warning by explicitly casting
the expression to the appropriate type.
> I'm wondering if this code should compile
Yes, it should
> a.c: In function `int main()':
> a.c:35: parse error before `>'
> a.c:36: parse error before `>'
It's a problem related with solving an ambiguity in the C++ grammar.
egcs 1.1 is taking the wrong path :-(
> Can anyone help me out?
You can work around this problem by using the `template' keyword at
some points, to disambiguate the use of the angle bracket, so that it
is not interpreted as the less-than operator. See below:
cout << A::template foo<double>() << endl ;
cout << a.template bar<double>() << endl ;
Furthermore, for some reason, egcs can't cope with the next fragment
of code either:
> template<typename T> T bar() { return foo<T>() ; }
I had to rewrite `foo<T>()' as `A::template foo<T>()' for it to
compile. Or did you mean `::foo<T>()'?
--
Alexandre Oliva
mailto:oliva@dcc.unicamp.br mailto:aoliva@acm.org
http://www.dcc.unicamp.br/~oliva
Universidade Estadual de Campinas, SP, Brasil