g++ 4.5.0 produces an ICE (segmentation fault) on the code in the
How-To-Repeat section.  The error is (the first non-blank line of the
example is line 1):

test.ii: In instantiation of ‘e<int>’:
test.ii:19:8:   instantiated from here
test.ii:16:32: internal compiler error: Segmentation fault

The errors are very fragile, however.  Any of the following changes make
the code compile:

- Remove struct d, or the definition of x inside it.
- Remove the U template parameter to struct d.
- Replace the use of f in d with c<T>::type.
- Remove either of the uses of a (e.g., changing the second line of
  struct d to "typename f::type x;"
- Remove either of the indirections through b or c (e.g., change the
  body of c to "typedef int type;" and then replace the uses of
  c<T>::type with c<T>).
- Remove the declaration of x in struct e.
- Remove the instantiation of struct e at the end of the file.

Changing struct e to a function or wrapping the declaration of x in
struct d in a member function does not work around this problem.  The
code that this was trimmed down from works on earlier versions of g++
(the actual code is from
libs/graph_parallel/test/distributed_connected_components_test.cpp in
Boost trunk r62270), and this exact code compiles on 4.1.2.

Environment:
System: Linux flowerpot.osl.iu.edu 2.6.18-194.3.1.el5 #1 SMP Sun May 2 04:17:42
EDT 2010 x86_64 x86_64 x86_64 GNU/Linux
Architecture: x86_64


host: x86_64-unknown-linux-gnu
build: x86_64-unknown-linux-gnu
target: x86_64-unknown-linux-gnu
configured with: ./configure --prefix=/u/jewillco/gcc45-install --enable-lto
--with-mpc=/u/jewillco/gcc45-install --with-mpfr=/u/jewillco/gcc45-install
--with-gmp=/u/jewillco/gcc45-install --with-ppl=/u/jewillco/gcc45-install
--with-cloog=/u/jewillco/gcc45-install --with-libelf=/u/jewillco/gcc45-install

How-To-Repeat:
Try to compile the following code (no flags required, but I tested with
-c; -fsyntax-only will also suffice to reproduce the problem):

template <class T> struct a {};

struct b {typedef int type;};

template <typename T>
struct c {typedef b type;};

template <typename T, typename U>
struct d {
  typedef typename c<T>::type f;
  a<typename f::type> x;
};

template <typename T>
struct e {
  a<typename c<T>::type::type> x;
};

e<int> y;


------- Comment #1 from jewillco at osl dot iu dot edu  2010-05-27 22:15 -------
Fix:
See description section for workarounds.


-- 
           Summary: g++ ICE on complicated template code
           Product: gcc
           Version: 4.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: jewillco at osl dot iu dot edu
 GCC build triplet: x86_64-unknown-linux-gnu
  GCC host triplet: x86_64-unknown-linux-gnu
GCC target triplet: x86_64-unknown-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44301

Reply via email to