https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81074
Bug ID: 81074 Summary: [7 regression] Nested template specialization causes segmentation fault Product: gcc Version: 7.1.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: jan at ypmania dot nl Target Milestone: --- Created attachment 41539 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=41539&action=edit Source file causing the segfault The attached test.cpp defines a partially specialized template inside of a template, i.e. as template <typename T> struct Outer { template <typename F, typename G> struct Inner {}; template <typename G> struct Inner<int, G> { ... }; }; and causes a segmentation fault while trying to resolve constexpr's inside Inner. The problem goes away if I flatten the structure, moving the inner templates into the global namespace. This is possibly related / duplicate of #55639; however, the code compiled fine under GCC 6 and 5 (compiler explorer verifies this). GCC Output: ------------------------------------------------------- $ gcc -v -save-temps test.cpp Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/7.1.1/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: /build/gcc/src/gcc/configure --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/ --enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++ --enable-shared --enable-threads=posix --enable-libmpx --with-system-zlib --with-isl --enable-__cxa_atexit --disable-libunwind-exceptions --enable-clocale=gnu --disable-libstdcxx-pch --disable-libssp --enable-gnu-unique-object --enable-linker-build-id --enable-lto --enable-plugin --enable-install-libiberty --with-linker-hash-style=gnu --enable-gnu-indirect-function --disable-multilib --disable-werror --enable-checking=release Thread model: posix gcc version 7.1.1 20170516 (GCC) COLLECT_GCC_OPTIONS='-v' '-save-temps' '-mtune=generic' '-march=x86-64' /usr/lib/gcc/x86_64-pc-linux-gnu/7.1.1/cc1plus -E -quiet -v -D_GNU_SOURCE test.cpp -mtune=generic -march=x86-64 -fpch-preprocess -o test.ii ignoring nonexistent directory "/usr/lib/gcc/x86_64-pc-linux-gnu/7.1.1/../../../../x86_64-pc-linux-gnu/include" #include "..." search starts here: #include <...> search starts here: /usr/lib/gcc/x86_64-pc-linux-gnu/7.1.1/../../../../include/c++/7.1.1 /usr/lib/gcc/x86_64-pc-linux-gnu/7.1.1/../../../../include/c++/7.1.1/x86_64-pc-linux-gnu /usr/lib/gcc/x86_64-pc-linux-gnu/7.1.1/../../../../include/c++/7.1.1/backward /usr/lib/gcc/x86_64-pc-linux-gnu/7.1.1/include /usr/local/include /usr/lib/gcc/x86_64-pc-linux-gnu/7.1.1/include-fixed /usr/include End of search list. COLLECT_GCC_OPTIONS='-v' '-save-temps' '-mtune=generic' '-march=x86-64' /usr/lib/gcc/x86_64-pc-linux-gnu/7.1.1/cc1plus -fpreprocessed test.ii -quiet -dumpbase test.cpp -mtune=generic -march=x86-64 -auxbase test -version -o test.s GNU C++14 (GCC) version 7.1.1 20170516 (x86_64-pc-linux-gnu) compiled by GNU C version 7.1.1 20170516, GMP version 6.1.2, MPFR version 3.1.5-p2, MPC version 1.0.3, isl version isl-0.18-GMP GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 GNU C++14 (GCC) version 7.1.1 20170516 (x86_64-pc-linux-gnu) compiled by GNU C version 7.1.1 20170516, GMP version 6.1.2, MPFR version 3.1.5-p2, MPC version 1.0.3, isl version isl-0.18-GMP GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 Compiler executable checksum: 74aace2f6deb87bb86dbfd7a28ebe524 test.cpp: In substitution of ‘template<unsigned char _fieldIdx, uint8_t Msg::* field> struct Outer<Msg>::Varint<_fieldIdx, unsigned char, field> [with unsigned char _fieldIdx = 1; uint8_t Msg::* field = &Msg::a]’: test.cpp:5:30: required from ‘constexpr const uint8_t HighestMaxFieldIdx<Outer<Msg>::Varint<1, unsigned char, &Msg::a> >::maxFieldIdx’ test.cpp:25:95: required from here test.cpp:5:30: internal compiler error: Segmentation fault static constexpr uint8_t maxFieldIdx = T::fieldIdx; ^~~~~~~~~~~