New internal compiler error

David Mazieres
Fri Jan 8 18:24:00 GMT 1999

The latest version of the egcs 1.2 branch has a new internal compiler
error on code that used to work a month or so ago.

% c++ -v
Reading specs from /usr/local/egcrap/lib/gcc-lib/i386-unknown-openbsd2.4/egcs-2.92.34/specs
gcc version egcs-2.92.34 19990108 (gcc2 ss-980609 experimental)
% c++ -c -O -Wall newbug.C 
newbug.C: In function `void xxx(int, struct ref<callback<void,int> >)':
newbug.C:110: Internal compiler error.
newbug.C:110: Please submit a full bug report to `'.
newbug.C:110: See <URL: > for details.



 * Since this now seems to matter:
 * Copyright 1999 David Mazieres.  No other person or organization
 * owns any part of this software.  Permission hereby granted to
 * include this program, modified versions, or derivative works in any
 * complier test suite distributed in any form under any license.
 * Permission is also granted to remove this copyright notice if the
 * compiler test suite is distributed under a license compatible with
 * version 2 of the GPL.  Permission also granted to use and
 * distribute this code under the GPL.  If the Free Software
 * Foundation ever publishes a document entitled something like
 * "suggested license for code snippets submitted as part of compiler
 * bug reports," then permission is additionally granted to use and
 * distribute the code under the terms of that document.  Blah, blah,
 * blah.  In short, no one is going to sue you for putting this code
 * in the egcs suite, even if you remove this wordy copyright.
 * Guaranteed.

#include <sys/types.h>

#define New new

struct refcount {
  int cnt;
  void refcount_inc () { cnt++; }
  void refcount_dec () { if (!--cnt) delete this; }
  refcount () : cnt (0) {}
  virtual ~refcount () {}

template<class T>
struct refcounted
  : virtual public refcount, public T
  refcounted () {}
  template<class A1>
  refcounted (const A1 &a1)
    : T (a1) {}
  template<class A1, class A2>
  refcounted (const A1 &a1, const A2 &a2)
    : T (a1, a2) {}
  template<class A1, class A2, class A3>
  refcounted (const A1 &a1, const A2 &a2, const A3 &a3)
    : T (a1, a2, a3) {}
  template<class A1, class A2, class A3, class A4>
  refcounted (const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4)
    : T (a1, a2, a3, a4) {}

template<class T>
struct ref {
  refcount *c;
  T *p;

  void refcount_inc () const { c->refcount_inc (); }
  void refcount_dec () const { c->refcount_dec (); }

  ref (const ref &r)
    : c (r), p (r) { refcount_inc (); }
  template<class U> ref (const U &r)
    : c (r), p (r) { refcount_inc (); }
  const ref &operator= (const ref &r)
    { r.refcount_inc (); refcount_dec (); c = r.c; p = r.p; return *this; }

  operator refcount *() const { return c; }
  operator T *() const { return p; }
  T *operator-> () const { return p; }
  T &operator* () const { return *p; }

template<class R, class B1 = void> class callback;

template<class R, class B1>
class callback {
  typedef ref<callback<R, B1> > ref;

  virtual R operator() (B1) = 0;
  virtual ~callback () {}

template<class R, class B1>
class callback_1_0
  : public callback<R, B1> {
  typedef R (*cb_t) (B1);
  cb_t f;
  callback_1_0 (cb_t ff)
    : f (ff) {}
  R operator() (B1 b1)
    { return f (b1); }

template<class R, class B1>
static inline refcounted<callback_1_0<R, B1> > *
wrap (R (*f) (B1))
  return New (refcounted<callback_1_0<R, B1> >) (f);

typedef callback<void, int>::ref cbi;

xxx (int fd, cbi cb)
  (*cb) (fd);

More information about the Gcc-bugs mailing list