https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123591
Bug ID: 123591
Summary: [16 Regression] ICE: Segmentation fault in
tree_to_uhwi using offsetof
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/hf4b9zcfb
The following c++ code crash gcc trunk.
But 12,13,14,15 with checking is fine.
Code:
```cpp
#include <cstddef>
template <class F = decltype([] <auto G = [] {
struct S {
int& out;
};
int offset = offsetof(S, out);
}> () {})>
void f(F op = {}) { op(); }
int main() { f(); }
```
Stack dump:
```
<source>: In lambda function:
<source>:3:14: error: types may not be defined in 'decltype' expressions
[-Wtemplate-body]
3 | struct S {
| ^
In file included from
/cefs/12/1260dcb9e807e35c18992817_gcc-trunk-20260114/include/c++/16.0.1/cstddef:52,
from <source>:1:
<source>: In substitution of 'template<auto G> <lambda()> [with auto G =
<missing>]':
required from 'void f(F) [with F = <lambda()>]'
<source>:8:23:
8 | void f(F op = {}) { op(); }
| ~~^~
required from here
<source>:10:15:
10 | int main() { f(); }
| ~^~
<source>:6:27: internal compiler error: Segmentation fault
6 | int offset = offsetof(S, out);
| ^
0x2929ea8 diagnostics::context::diagnostic_impl(rich_location*,
diagnostics::metadata const*, diagnostics::option_id, char const*,
__va_list_tag (*) [1], diagnostics::kind)
???:0
0x291ec6b internal_error(char const*, ...)
???:0
0x189e9b5 tree_to_uhwi(tree_node const*)
???:0
0xe94849 fold_offsetof(tree_node*, tree_node*, tree_code)
???:0
0xd819d5 tsubst_lambda_expr(tree_node*, tree_node*, int, tree_node*)
???:0
0xd92261 tsubst_template_arg(tree_node*, tree_node*, int, tree_node*)
???:0
0xdbc781 fn_type_unification(tree_node*, tree_node*, tree_node*, tree_node*
const*, unsigned int, tree_node*, unification_kind_t, int, conversion**, bool,
bool)
???:0
0xb535f2 build_op_call(tree_node*, vec<tree_node*, va_gc, vl_embed>**, int)
???:0
0xddedf5 finish_call_expr(tree_node*, vec<tree_node*, va_gc, vl_embed>**, bool,
bool, int)
???:0
0xdb9b6d instantiate_decl(tree_node*, bool, bool)
???:0
0xdc357a instantiate_pending_templates(int)
???:0
0xc328a8 c_parse_final_cleanups()
???:0
0xec9428 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
```