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

            Bug ID: 123648
           Summary: [14/15/16 Regression] ICE in
                    cxx_eval_store_expression, at cp/constexpr.cc:8075
                    during constexpr evaluation of nested struct in lambda
           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/as441nxe3
While reducing bug 123647, I found another related but distinct ICE. Although
the test case is similar, this one crashes at a different location.
And this one only goes back to 14.3 with checking.


Code:
```cpp
auto make_recursive_lambda() {
  return [](auto, int a ) -> int {
    struct MyStruct {
      int stackList = stackList;
    };
     struct {
      MyStruct S[2]; // replace {} with ; cause bug 123647
    } container;
  }
}
template <T> function() {
  auto rec_lambda = make_recursive_lambda();
  constexpr int result = rec_lambda(rec_lambda, 5);
}
```

Stack dump:
```
<source>: In lambda function:
<source>:9:3: warning: no return statement in function returning non-void
[-Wreturn-type]
    9 |   }
      |   ^
<source>: In function 'auto make_recursive_lambda()':
<source>:9:4: error: expected ';' before '}' token
    9 |   }
      |    ^
      |    ;
   10 | }
      | ~   
<source>: At global scope:
<source>:11:11: error: 'T' has not been declared
   11 | template <T> function() {
      |           ^
<source>:11:14: error: ISO C++ forbids declaration of 'function' with no type
[-fpermissive]
   11 | template <T> function() {
      |              ^~~~~~~~
<source>: In function 'int function()':
in 'constexpr' expansion of
'rec_lambda.make_recursive_lambda()::<lambda(auto:1, int)>((rec_lambda,
make_recursive_lambda()::<lambda(auto:1, int)>()), 5)'
<source>:13:36:   
   13 |   constexpr int result = rec_lambda(rec_lambda, 5);
      |                          ~~~~~~~~~~^~~~~~~~~~~~~~~
in 'constexpr' expansion of 'container.make_recursive_lambda()::<lambda(auto:1,
int)>::<unnamed struct>::<constructor>()'
<source>:8:7:   
    8 |     } container;
      |       ^~~~~~~~~
<source>:6:13: internal compiler error: in cxx_eval_store_expression, at
cp/constexpr.cc:8075
    6 |      struct {
      |             ^
0x2950618 diagnostics::context::diagnostic_impl(rich_location*,
diagnostics::metadata const*, diagnostics::option_id, char const*,
__va_list_tag (*) [1], diagnostics::kind)
        ???:0
0x29453db internal_error(char const*, ...)
        ???:0
0xb1eaa6 fancy_abort(char const*, int, char const*)
        ???:0
0xb8b11f cxx_eval_constant_expression(constexpr_ctx const*, tree_node*,
value_cat, bool*, bool*, tree_node**)
        ???:0
0xb8d0fd cxx_eval_constant_expression(constexpr_ctx const*, tree_node*,
value_cat, bool*, bool*, tree_node**)
        ???:0
0xb8b11f cxx_eval_constant_expression(constexpr_ctx const*, tree_node*,
value_cat, bool*, bool*, tree_node**)
        ???:0
0xb8b911 cxx_eval_constant_expression(constexpr_ctx const*, tree_node*,
value_cat, bool*, bool*, tree_node**)
        ???:0
0xb8c515 cxx_eval_constant_expression(constexpr_ctx const*, tree_node*,
value_cat, bool*, bool*, tree_node**)
        ???:0
0xb8c060 cxx_eval_constant_expression(constexpr_ctx const*, tree_node*,
value_cat, bool*, bool*, tree_node**)
        ???:0
0xb8bd60 cxx_eval_constant_expression(constexpr_ctx const*, tree_node*,
value_cat, bool*, bool*, tree_node**)
        ???:0
0xb8c2e4 cxx_eval_constant_expression(constexpr_ctx const*, tree_node*,
value_cat, bool*, bool*, tree_node**)
        ???:0
0xb8c515 cxx_eval_constant_expression(constexpr_ctx const*, tree_node*,
value_cat, bool*, bool*, tree_node**)
        ???:0
0xb8c060 cxx_eval_constant_expression(constexpr_ctx const*, tree_node*,
value_cat, bool*, bool*, tree_node**)
        ???:0
0xb8ca35 cxx_eval_constant_expression(constexpr_ctx const*, tree_node*,
value_cat, bool*, bool*, tree_node**)
        ???:0
0xb8bd60 cxx_eval_constant_expression(constexpr_ctx const*, tree_node*,
value_cat, bool*, bool*, tree_node**)
        ???:0
0xb8bd60 cxx_eval_constant_expression(constexpr_ctx const*, tree_node*,
value_cat, bool*, bool*, tree_node**)
        ???:0
0xb8c2e4 cxx_eval_constant_expression(constexpr_ctx const*, tree_node*,
value_cat, bool*, bool*, tree_node**)
        ???:0
0xe6d8df store_init_value(tree_node*, tree_node*, vec<tree_node*, va_gc,
vl_embed>**, int)
        ???:0
0xc27c62 cp_finish_decl(tree_node*, tree_node*, bool, tree_node*, int,
cp_decomp*)
        ???:0
0xd647e3 c_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