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]
Other format: [Raw text]

GCC bug when using typeof


Hi,

I tried to compile the following program, but I got the following
error. Is it a bug of GCC? Has it been fixed in a newer version GCC?

g++ -Wall -W -pedantic  -g -c -o main-g.o main.cc
main.cc:57: internal compiler error: in write_type, at cp/mangle.c:1651
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.
For Debian GNU/Linux specific bug reporting instructions,
see <URL:file:///usr/share/doc/gcc-4.1/README.Bugs>.
Preprocessed source stored into /tmp/ccEcnj4W.out file, please attach
this to your bugreport.

Currently, I'm using g++ of the following version.

g++ (GCC) 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Thanks,
Peng

#include <iostream>

namespace A {

  template <typename T>
    class X {
      public:
        X() { }
        X(T t) : _t(t) { }
        const T &the_t() const { return _t; }
      private:
        T _t;
    };

  template <typename T1, typename T2>
    struct multiply_traits;

  template <typename T1, typename T2>
    struct multiply_traits<X<T1>, T2> {
      typedef X<T1> result_type;
    };

  template <typename T1, typename T2>
    typename multiply_traits<X<T1>, T2>::result_type operator*(const
X<T1> &x, const T2 &t) {
      return X<T1>(x.the_t() * t);
    }

}

namespace B {

  template <typename T>
    class Y {
      public:
        Y(T t) : _t(t) { }
        const T &the_t() const { return _t; }
      private:
        T _t;
    };

  template <typename T1, typename T2>
    Y<typeof(T1() * T2())>
    operator*(const Y<T1> &y, const T2 &t) {
      return Y<T1>(y.the_t() * t);
    }
}

int main () {
  A::X<int> x(2);
  B::Y<A::X<int> > y(x);

  std::cout << (x * 3).the_t() << std::endl;
  std::cout << (y * 5).the_t().the_t() << std::endl;
}


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