https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123536
Bug ID: 123536
Summary: [16 Regression] ICE in mark_use, at cp/expr.cc:190
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/xxd57WKzh
The following c++ code crash gcc trunk. But gcc 13,14,15 is fine.
Code:
```cpp
volatile int globalCounter = 0;
template <typename Func> constexpr auto inline_invoke(Func func) {
volatile int &counterRef = globalCounter;
auto lamda = []() { counterRef++; }
}
```
Stack dump:
```
<source>: In function 'constexpr auto inline_invoke(Func)':
<source>:4:17: error: 'x' was not declared in this scope [-Wtemplate-body]
4 | auto lamda = [x]() { counterRef++; }
| ^
<source>: In lambda function:
<source>:4:34: error: 'counterRef' is not captured [-Wtemplate-body]
4 | auto lamda = [x]() { counterRef++; }
| ^~
<source>:4:18: note: the lambda has no capture-default
4 | auto lamda = [x]() { counterRef++; }
| ^
<source>:3:17: note: 'volatile int& counterRef' declared here
3 | volatile int &counterRef = globalCounter;
| ^~~~~~~~~~
<source>:4:34: internal compiler error: in mark_use, at cp/expr.cc:190
4 | auto lamda = [x]() { counterRef++; }
| ^~
0x2924d48 diagnostics::context::diagnostic_impl(rich_location*,
diagnostics::metadata const*, diagnostics::option_id, char const*,
__va_list_tag (*) [1], diagnostics::kind)
???:0
0x2919b0b internal_error(char const*, ...)
???:0
0xb16bf2 fancy_abort(char const*, int, char const*)
???:0
0xe2e02e cp_build_unary_op(tree_code, tree_node*, bool, int)
???:0
0xb52546 build_new_op(op_location_t const&, tree_code, int, tree_node*,
tree_node*, tree_node*, tree_node*, tree_node**, int)
???:0
0xe2c6e4 build_x_unary_op(unsigned long, tree_code, cp_expr, tree_node*, int)
???:0
0xddb15f finish_increment_expr(cp_expr, tree_code)
???:0
0xd573b3 c_parse_file()
???:0
0xec8de9 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
```