https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103968
Bug ID: 103968 Summary: ICE and segfault when instantiating template with lvalue ref argument and nested template type Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: aliaume.morel at baracoda dot com Target Milestone: --- The following compiles with clang, GCC 10.3, but gives an ICE on GCC 11.1 and 12.0.0 (20220110) - tested on Godbolt (https://godbolt.org/z/db5EjWGWa): ``` template <typename Opt, Opt const& options> struct trait { template <typename T> struct NonInstantiated{}; }; struct Options {}; template <typename T> struct Widget { static constexpr auto c_options = Options{}; using Trait = trait<decltype(c_options), c_options>; }; Widget<int>::Trait b{}; // Crashes GCC > 10.3 ``` Stack trace: <source>: In instantiation of 'struct trait<const Options, ((const Options&)Widget<T>::c_options)>': <source>:17:20: required from here <source>:5:12: internal compiler error: Segmentation fault 5 | struct NonInstantiated{}; | ^~~~~~~~~~~~~~~ 0x1780bf9 internal_error(char const*, ...) ???:0 0x7f628d instantiate_class_template(tree_node*) ???:0 0x829553 complete_type(tree_node*) ???:0 0x6e6d2b start_decl_1(tree_node*, bool) ???:0 0x6f6587 start_decl(cp_declarator const*, cp_decl_specifier_seq*, int, tree_node*, tree_node*, tree_node**) ???:0 0x7c0cab c_parse_file() ???:0 0x892aa2 c_common_parse_file() ???:0 - This is reproducible in C++17 and C++20 mode. - In C++20 mode, removing the lvalue ref from the second template argument in `struct trait` doesn't trigger the ICE and builds successfully. - If `Widget` is a non-template type, it doesn't trigger the ICE and builds succesfully.