This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
egcs-1.1.2: Problems with forward declarations and typedefs
- To: egcs-bugs at egcs dot cygnus dot com
- Subject: egcs-1.1.2: Problems with forward declarations and typedefs
- From: Marc-Oliver Gewaltig <gewaltig at biologie dot uni-freiburg dot de>
- Date: Thu, 1 Jul 1999 10:44:18 +0200 (MEST)
- cc: marc-oliver dot gewaltig at hre-ftr dot f dot rd dot honda dot co dot jp
Hi,
I think I have located a bug in egcs-1.1.2. The problem is illustrated
by
the following simple example:
a.h
----
template <class T>
class B: public T
{
// ...
};
typedef B<A> MyB;
c.h
----
class MyB; // forward declaration to reduce header dependencies
class C
{
public:
// ...
void f(MyB &) const;
};
c.cc
----
#include "a.h"
#include "c.h"
void C::f(MyB &mb) const
{
// ...
}
If I compile c.cc, I get an error stating that I redefined MyB.
> g++ c.cc -o c
In file included from c.cc:2:
c.h:1: conflicting types for `struct MyB'
a.h:13: previous declaration as `typedef class B<A> MyB'
Now I wonder whether I misinterpreted the ISO C++ Standard, or
whether this is a problem with egcs (specs follow).
According to the standard, a typedef to a class introduces a class-name
(7.3.1,4 "The typedef specifier") so the forward declaration should be
legal.
Am I missing something here?
Thanks in advance,
Marc-Oliver Gewaltig
-----
Reading specs from
/opt/gnu/lib/gcc-lib/sparc-sun-solaris2.6/egcs-2.91.66/specs
gcc version egcs-2.91.66 19990314 (egcs-1.1.2 release)
/opt/gnu/lib/gcc-lib/sparc-sun-solaris2.6/egcs-2.91.66/cpp -lang-c++ -v
-undef -D__GNUC__=2 -D__GNUG__=2 -D__cplusplus -D__GNUC_MINOR__=91
-Dsparc -Dsun -Dunix -D__svr4__ -D__SVR4 -D__sparc__ -D__sun__
-D__unix__ -D__svr4__ -D__SVR4 -D__sparc -D__sun -D__unix -Asystem(unix)
-Asystem(svr4) -D__EXCEPTIONS -D__GCC_NEW_VARARGS__ -Acpu(sparc)
-Amachine(sparc) c.cc /var/tmp/cckBqHUS.ii
GNU CPP version egcs-2.91.66 19990314 (egcs-1.1.2 release) (sparc)
#include "..." search starts here:
#include <...> search starts here:
/opt/gnu/include/g++
/usr/local/include
/opt/gnu/sparc-sun-solaris2.6/include
/opt/gnu/lib/gcc-lib/sparc-sun-solaris2.6/egcs-2.91.66/include
/usr/include
End of search list.
/opt/gnu/lib/gcc-lib/sparc-sun-solaris2.6/egcs-2.91.66/cc1plus
/var/tmp/cckBqHUS.ii -quiet -dumpbase c.cc -version -o
/var/tmp/ccoRkRbI.s
GNU C++ version egcs-2.91.66 19990314 (egcs-1.1.2 release)
(sparc-sun-solaris2.6) compiled by GNU C version egcs-2.91.66 19990314
(egcs-1.1.2 release).
In file included from c.cc:2:
c.h:1: conflicting types for `struct MyB'
a.h:13: previous declaration as `typedef class B<A> MyB'
------------------------
Marc-Oliver Gewaltig (Dipl. Phys.)
Future Technology Research Tel. +49-(0)69-89011-739
HONDA R&D Europe GmbH Fax. +49-(0)69-89011-749
Carl-Legien-Str. 30
D-63073 Offenbach/Main
e-mail. Marc-Oliver.Gewaltig@hre-ftr.f.rd.honda.co.jp
gewaltig@biologie.uni-freiburg.de