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

            Bug ID: 123658
           Summary: ICE in tsubst_expr (at cp/pt.cc) when lambda in
                    template accesses member of local constexpr struct
                    without capture
           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/jhcq6Mcao
The following c++ code crash gcc trunk.
And goes back to 12.1 with checking.
But gcc 15.2 without checking and clang accept it.

Code:
```cpp
struct Nested {
  int value;
};
constexpr auto evaluate() {
  Nested __trans_tmp_1{};
  return __trans_tmp_1;
}
template <class T, int S> void f(T (&&)[S]) {
  constexpr auto x = evaluate();
  [] { x.value ?: 0; };
}
using arr = int[2];
int main() { f(arr{}); }
```

Stack dump:
```
<source>: In instantiation of 'void f(T (&&)[S]) [with T = int; int S = 2]':
required from here
<source>:13:15:   
   13 | int main() { f(arr{}); }
      |              ~^~~~~~~
<source>:10:8: internal compiler error: in tsubst_expr, at cp/pt.cc:22796
   10 |   [] { x.value ?: 0; };
      |        ^
0x2950a78 diagnostics::context::diagnostic_impl(rich_location*,
diagnostics::metadata const*, diagnostics::option_id, char const*,
__va_list_tag (*) [1], diagnostics::kind)
        ???:0
0x294583b internal_error(char const*, ...)
        ???:0
0xb1ec34 fancy_abort(char const*, int, char const*)
        ???:0
0xd8f0de tsubst_lambda_expr(tree_node*, tree_node*, int, tree_node*)
        ???:0
0xdc7c3d instantiate_decl(tree_node*, bool, bool)
        ???:0
0xdd177a instantiate_pending_templates(int)
        ???:0
0xc3cd58 c_parse_final_cleanups()
        ???:0
0xeeed78 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
```

Reply via email to