https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69903

            Bug ID: 69903
           Summary: Function template specialization with CRTP-class
                    causes compiler segfault
           Product: gcc
           Version: 4.9.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: tolstokor at gmail dot com
  Target Milestone: ---

Created attachment 37756
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=37756&action=edit
Preprocessed source file

The bug exists in versions from 4.8.1 to latest 5.3.0, including ARM and ARM64
compiler versions, with any compiler flags and optimization level. Platform
independent: most Linux distributives and MinGW (Windows) version crashes while
compiling this code:

// CRTP
template <typename T>
struct A {

  // Default behavior
  template <int i>
  inline static void f() {
    volatile int x = i;
  };

  inline static void F() {
    T::template f<0>();
    T::template f<1>();
    T::template f<2>();
  }
};

struct B : A<B> { /* empty */ };

// Specification for i == 2
template<>
void B::f<2>() {
  volatile int y = 777;
};

int main() {
  B::F();
}

Error messages like this:

/tmp/gcc-explorer-compiler116122-74-ozif0b/example.cpp: In instantiation of
'static void A<T>::f() [with int i = 2; T = B]':
13 : required from 'static void A<T>::F() [with T = B]'
26 : required from here
7 : internal compiler error: Segmentation fault
volatile int x = i;
^
****
Please submit a full bug report,
with preprocessed source if appropriate.
See <file:///usr/share/doc/gcc-4.8/README.Bugs> for instructions.
Preprocessed source stored into /tmp/ccmxbU4L.out file, please attach this to
your bugreport.
Compilation failed

Reply via email to