[Bug c++/126754] New: [16/17 Regression] ICE in tsubst_expr, at cp/pt.cc:23354

haakonsv at gmail dot com via Gcc-bugs <[email protected]>
Newsgroups gmane.comp.gcc.bugs
Message-ID <[email protected]/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126754

            Bug ID: 126754
           Summary: [16/17 Regression] ICE in tsubst_expr, at
                    cp/pt.cc:23354
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: haakonsv at gmail dot com
  Target Milestone: ---

Compiler Explorer: https://godbolt.org/z/av78K7nqc

The following code crashes GCC trunk. All versions of 16.X are affected, while
GCC 15.X and earlier versions are not affected.

I've tried bisecting GCC, it seems like
https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=24efdb0974 is the first bad
commit.

Code:
```
struct S { int i; };
int main() {
    constexpr S a{1};
    const auto f = [](auto b) {
        return 1 - a.i;  // this expression must be independent of b in order
to trigger the crash
    };
    return f(0);
}
```

Stack dump:
```
<source>: In instantiation of 'main()::<lambda(auto:1)> [with auto:1 = int]':
<source>:7:13:   required from here
    7 |     return f(0);
      |            ~^~~
<source>:5:20: internal compiler error: in tsubst_expr, at cp/pt.cc:23354
    5 |         return 1 - a.i;  // this expression must be independent of b in
order to trigger the crash
      |                    ^
0x2b97f28 diagnostics::context::diagnostic_impl(rich_location*,
diagnostics::metadata const*, diagnostics::option_id, char const*,
__va_list_tag (*) [1], diagnostics::kind)
        ???:0
0x2b8cb6b internal_error(char const*, ...)
        ???:0
0xb40b7e fancy_abort(char const*, int, char const*)
        ???:0
0xdfb9ad instantiate_decl(tree_node*, bool, bool)
        ???:0
0xc60de3 maybe_instantiate_decl(tree_node*)
        ???:0
0xc62dc7 mark_used(tree_node*, int)
        ???:0
0xb7e593 build_op_call(tree_node*, vec<tree_node*, va_gc, vl_embed>**, int)
        ???:0
0xe3a3d6 finish_call_expr(tree_node*, vec<tree_node*, va_gc, vl_embed>**, bool,
bool, int)
        ???:0
0xd96823 c_parse_file()
        ???:0
0xf29cf9 c_common_parse_file()
        ???:0
```
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.