https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123594
Bug ID: 123594
Summary: [14/15/16 Regression] ICE: Segmentation fault at
build_new_op/build_x_binary_op with nested generic
lambdas and typeid
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/GM1TsadTj
The following valid c++ code crash gcc trunk.
And goes back to 14.1 with checking.
But gcc 12,13 accept it.
Code:
```cpp
#include <typeinfo>
int main() {
auto foo = [=](auto) {
const std::type_info &type = typeid(nullptr);
auto g = [&]() {
return []() {
if (type == typeid(nullptr)) {
}
};
};
};
}
```
Stack dump:
```
<source>: In lambda function:
<source>:7:35: error: 'type' is not captured [-Wtemplate-body]
7 | if (type == typeid(nullptr)) {
| ^
<source>:6:15: note: the lambda has no capture-default
6 | return []() {
| ^
<source>:4:27: note: 'const std::type_info& type' declared here
4 | const std::type_info &type = typeid(nullptr);
| ^~~~
<source>:7:35: internal compiler error: Segmentation fault
7 | if (type == typeid(nullptr)) {
| ^
0x292a498 diagnostics::context::diagnostic_impl(rich_location*,
diagnostics::metadata const*, diagnostics::option_id, char const*,
__va_list_tag (*) [1], diagnostics::kind)
???:0
0x291f25b internal_error(char const*, ...)
???:0
0xb51e46 build_new_op(op_location_t const&, tree_code, int, tree_node*,
tree_node*, tree_node*, tree_node*, tree_node**, int)
???:0
0xe22a92 build_x_binary_op(op_location_t const&, tree_code, tree_node*,
tree_code, tree_node*, tree_code, tree_node*, tree_node**, int)
???:0
0xd58163 c_parse_file()
???:0
0xec9d69 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
```