This is the mail archive of the gcc@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]

member template functions && strange warnings


Hi,

    I send the following messages in comp.lang.c++ and gnu.g++.help
yesterday morning but haven't had any answer yet. I now it hasn't been
that long but I 'm sort of in a hurry. If anyone has an explanation, I'd
greatly apreciate it. sorry if this isn't the list for such messages.

    many thanks.

        Alex,

ps: I run gcc version egcs-2.91.57 19980901 (egcs-1.1 release) under
SunOS mrrc4 5.6 Generic_105181-03 sun4u sparc SUNW,Ultra-5_10

Message-ID: <35F43EEB.ECEA2D12@epidaure.inria.fr>
Date: Mon, 07 Sep 1998 20:15:39 +0000
From: Alexandre Guimond <guimond@epidaure.inria.fr>
X-Mailer: Mozilla 4.04 [en] (X11; I; SunOS 5.6 sun4u)
MIME-Version: 1.0
Newsgroups: gnu.g++.help,comp.lang.c++
Subject: strang warnings or just bad code?
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Hello,

    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
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)'
throw.c:38: warning: passing `F' chooses `int' over `long int'
throw.c:38: warning:   in call to `ostream::operator <<(int)'
throw.c:38: warning: passing `F' chooses `int' over `unsigned int'
throw.c:38: warning:   in call to `ostream::operator <<(int)'

The two first lines I just don't understand. The other I can get rid of
by remogin the -Wall option but that's not really the solution I'm
looking for :)

Thanks for the help.

    Alex.

ps: gcc version egcs-2.91.57 19980901 (egcs-1.1 release)

#include <iostream>

template<typename T>
class E
{
   public:
      class B {} ;
} ;

template<typename T>
class A
{
   public:
      void
      foo(T* t)
  throw(typename E<T*>::B) ;
} ;

template<typename T>
void
A<T>::foo(T* t)
   throw(typename E<T*>::B)
{
   *t += 1 ;
}

enum F { f1, f2 } ;

int
main()
{
   A<int> a ;
   int i = 0 ;

   a.foo( &i ) ;

   cout << i << endl ;
   cout << f1 << endl ;
}



Message-ID: <35F3B4EB.630D8824@epidaure.inria.fr>
Date: Mon, 07 Sep 1998 10:26:51 +0000
From: Alexandre Guimond <guimond@epidaure.inria.fr>
X-Mailer: Mozilla 4.04 [en] (X11; I; SunOS 5.6 sun4u)
MIME-Version: 1.0
Newsgroups: comp.lang.c++,gnu.g++.help
Subject: member templates
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Hello there,

    I'm wondering if this code should compile, and if so why it doesn't
under

gcc version egcs-2.91.57 19980901 (egcs-1.1 release)

with the command "g++ a.c". (I get the error :

a.c: In function `int main()':
a.c:35: parse error before `>'
a.c:36: no match for `_IO_ostream_withassign & << T (A::)()'
/usr/local/include/g++/iostream.h:77: candidates are: ostream::operator
<<(char)
[...]
a.c:36: parse error before `>'

Can anyone help me out?

Thanks for the help,

    Alex.

>>> a.c >>>

#include <iostream>

class A
{
   public:
      template<typename T>
      static
      T
      foo()
      {
  return T(1) ;
      }

      template<typename T>
      T
      bar()
      {
  return foo<T>() ;
      }
} ;

template<typename T>
T
foo()
{
   return T(1) ;
}

int
main()
{
   A a ;

   cout << foo<double>() << endl ;
   cout << A::foo<double>() << endl ;
   cout << a.bar<double>() << endl ;
}





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