https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61850
Bug ID: 61850 Summary: g++ crashes (SEGV) on the following endless template instantiation Product: gcc Version: 4.9.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: akim.demaille at gmail dot com Hi, I'm toying with templates and enable_if to try to enforce commutativity on some operator. In the course of these experiments, I fell on the following crash. I have not tried to scale it down, sorry about that. I know my program is wrong. Maybe eventually I will spend some time to make it smaller, but maybe that's already good for you. Cheers. #include <iostream> template <typename V1, typename V2, typename Enable = void> struct join_impl { enum { forward = true }; }; /// T without reference or const/volatile qualifiers. template <typename T> using base_t = typename std::remove_cv<typename std::remove_reference<T>::type>::type; template <typename V1, typename V2> typename join_impl<base_t<V1>, base_t<V2>>::type join(V1 v1, V2 v2) { return join_impl<base_t<V1>, base_t<V2>>::join(v1, v2); } template <typename T> struct join_impl<T, T> { enum { forward = false }; using type = T; static type join(type v1, type v2) { return v1 * v2; } }; template <typename T1, typename T2> struct join_impl<T1, T2, typename std::enable_if<join_impl<T2, T1>::forward>::type> { enum { forward = false }; using super = join_impl<T2, T1>; using type = typename super::type; static type join(T1 v1, T2 v2) { return super::join(v2, v1); } }; int main() { int i = 20; float f = 0.1; #define ECHO(S) std::cerr << #S": " << S << '\n' // ECHO(::join(i, i)); ECHO(::join(i, f)); ECHO(::join(f, i)); ECHO(::join(f, f)); } g++-mp-4.9 -Wall -std=c++11 v4-without-wrapper.cc g++-mp-4.9: error: v4-without-wrapper.cc: No such file or directory g++-mp-4.9: fatal error: no input files compilation terminated. g++-mp-4.9 (MacPorts gcc49 4.9-20140416_2) 4.9.0 20140416 (prerelease) Copyright (C) 2014 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.