g++ segfaults compiling C++ code
>Submitter-Id: net
>Originator: Olly Betts
>Organization: none
>Confidential: no
>Synopsis: Compiling the attach code causes g++ to segfault
>Severity: serious
>Priority: medium
>Category: c++
>Class: ice-on-legal-code
>Release: 3.0 (Debian) (Debian testing/unstable)
>Environment:
System: Linux roadkill 2.2.19 #1 Sat Jun 9 14:48:14 EST 2001 i686 unknown
Architecture: i686
host: i386-pc-linux-gnu
build: i386-pc-linux-gnu
target: i386-pc-linux-gnu
configured with: ../src/configure -v --enable-languages=c,c++,java,f77,proto,objc --prefix=/usr --infodir=/share/info --mandir=/share/man --enable-shared --with-gnu-as --with-gnu-ld --with-system-zlib --enable-long-long --enable-nls --without-included-gettext --disable-checking --enable-threads=posix --enable-java-gc=boehm --with-cpp-install-dir=bin --enable-objc-gc i386-linux
>Description:
Compiling the attached file causes g++ to segfault.
I believe the code is legal C++ apart from the template parameter
being declared friend, and since g++ only makes that a warning, it
presumably is allowing the code as an extension to ISO C++.
>How-To-Repeat:
Compile with:
g++-3.0 -O -pedantic -c gcc3.cc
class A {
public:
class I;
I *i;
A(const A&);
virtual ~A()=0;
};
class S {
public:
S(const int &);
~S() { try { } catch(S&) { } }
};
class B {
private:
int m;
public:
bool d() const;
class T {};
};
template <class T> class P {
friend T;
private:
T *d;
public:
T *g() const;
P(const P &);
~P();
template <class U> P(const P<U> &);
};
inline bool B::d() const { S s(m); return 1; }
template <class T> inline P<T>::P(const P &o) : d(o.d) {}
template <class T> inline P<T>::~P() { d->d(); }
template <class T>
template <class U> inline P<T>::P(const P<U> &o) : d(o.g()) {}
template <class T> inline T*P<T>::g() const { return d; }
class A::I {
public:
class D;
P<D> d;
};
class A::I::D : public B {
public:
D();
};
A::A(const A &o): i(new A::I(*o.i)) {}
>Fix:
Compiling without optimisation seems to avoid this problem:
g++-3.0 -pedantic -c gcc3.cc
Reply to: