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

            Bug ID: 123682
           Summary: ICE (Segfault) in register_local_specialization during
                    instantiation of static member in local class within a
                    template
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jirehguo at tju dot edu.cn
  Target Milestone: ---

Compiler Explorer: https://godbolt.org/z/nG6PY7W5W
The following c++ code crash gcc trunk.
Goes back to 10.3 with checking.


Code:
```cpp
template <typename C, typename T>
struct NestedTemplate {
      static constexpr bool check() {
        auto recurse = []() -> int {
          return 0;
        };
        struct Y {
          static auto member = recurse();
        };
      }
};

using Nested = NestedTemplate<int, int>;
bool result = Nested::check();
```

Stack dump:
```
<source>: In static member function 'static constexpr bool NestedTemplate<C,
T>::check()':
<source>:8:23: error: local class 'struct NestedTemplate<C, T>::check()::Y'
shall not have static data member 'auto NestedTemplate<C,
T>::check()::Y::member' [-Wtemplate-body]
    8 |           static auto member = recurse();
      |                       ^~~~~~
<source>: In instantiation of 'auto NestedTemplate<int,
int>::check()::Y::member':
required from 'struct NestedTemplate<int, int>::check()::Y'
<source>:8:23:   
required from 'static constexpr bool NestedTemplate<C, T>::check() [with C =
int; T = int]'
<source>:9:9:   
    9 |         };
      |         ^
required from here
<source>:14:28:   
   14 | bool result = Nested::check();
      |               ~~~~~~~~~~~~~^~
<source>:4:14: internal compiler error: Segmentation fault
    4 |         auto recurse = []() -> int {
      |              ^~~~~~~
0x2950a78 diagnostics::context::diagnostic_impl(rich_location*,
diagnostics::metadata const*, diagnostics::option_id, char const*,
__va_list_tag (*) [1], diagnostics::kind)
        ???:0
0x294583b internal_error(char const*, ...)
        ???:0
0xd818e4 register_local_specialization(tree_node*, tree_node*)
        ???:0
0xdc7b69 instantiate_decl(tree_node*, bool, bool)
        ???:0
0xc28f97 cp_finish_decl(tree_node*, tree_node*, bool, tree_node*, int,
cp_decomp*)
        ???:0
0xc3a2be finish_static_data_member_decl(tree_node*, tree_node*, bool,
tree_node*, int)
        ???:0
0xdcfdc0 instantiate_class_template(tree_node*)
        ???:0
0xdc7c3d instantiate_decl(tree_node*, bool, bool)
        ???:0
0x18eb79c walk_tree_1(tree_node**, tree_node* (*)(tree_node**, int*, void*),
void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*,
tree_node* (*)(tree_node**, int*, tree_node* (*)(tree_node**, int*, void*),
void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*))
        ???:0
0x18eb9c0 walk_tree_1(tree_node**, tree_node* (*)(tree_node**, int*, void*),
void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*,
tree_node* (*)(tree_node**, int*, tree_node* (*)(tree_node**, int*, void*),
void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*))
        ???:0
0x18ef427 walk_tree_without_duplicates_1(tree_node**, tree_node*
(*)(tree_node**, int*, void*), void*, tree_node* (*)(tree_node**, int*,
tree_node* (*)(tree_node**, int*, void*), void*, hash_set<tree_node*, false,
default_hash_traits<tree_node*> >*))
        ???:0
0xe6ddb5 store_init_value(tree_node*, tree_node*, vec<tree_node*, va_gc,
vl_embed>**, int)
        ???:0
0xc285d6 cp_finish_decl(tree_node*, tree_node*, bool, tree_node*, int,
cp_decomp*)
        ???:0
0xd64c03 c_parse_file()
        ???:0
0xeeed49 c_common_parse_file()
        ???:0
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
Compiler returned: 1
```

Reply via email to