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]

c++/3576: g++ segfaults compiling C++ code



>Number:         3576
>Category:       c++
>Synopsis:       Compiling the attach code causes g++ to segfault
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          ice-on-legal-code
>Submitter-Id:   net
>Arrival-Date:   Thu Jul 05 13:26:01 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     Olly Betts
>Release:        3.0 (Debian) (Debian testing/unstable)
>Organization:
none
>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
>Release-Note:
>Audit-Trail:
>Unformatted:


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