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

            Bug ID: 123533
           Summary: [16 Regression] ICE in
                    build_data_member_initialization, at
                    cp/constexpr.cc:466
           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/Yc1EsWWGj
The following c++ code crash gcc trunk with -std=c++23 flag. But gcc 13,14,15
is fine.

Code:
```cpp
#include <atomic>
#include <iostream>
template <typename T> struct SharedObject { std::atomic<T> value; };
struct foo {
  constexpr foo(int a);
  int a, b, c;
};
constexpr foo make_foo(int a);
foo __trans_tmp_1;
constexpr foo::foo(int a) : foo{__trans_tmp_1} {
  SharedObject<int> obj;
  for (int i = a; i < a; ++i)
    ;
    obj.value.load(std::memory_order_relaxed);
}
constexpr const foo f{3};
```

Stack dump:
```
<source>:9:5: error: no matching function for call to 'foo::foo()'
    9 | foo __trans_tmp_1;
      |     ^~~~~~~~~~~~~
  • there are 3 candidates
    • candidate 1: 'constexpr foo::foo(int)'
      <source>:5:13:
          5 |   constexpr foo(int a);
            |             ^~~
      • candidate expects 1 argument, 0 provided
    • candidate 2: 'constexpr foo::foo(const foo&)'
      <source>:4:8:
          4 | struct foo {
            |        ^~~
      • candidate expects 1 argument, 0 provided
    • candidate 3: 'constexpr foo::foo(foo&&)'
      • candidate expects 1 argument, 0 provided
<source>:16:24: error: 'constexpr foo::foo(int)' called in a constant
expression
   16 | constexpr const foo f{3};
      |                        ^
<source>:10:11: note: 'constexpr foo::foo(int)' is not usable as a 'constexpr'
function because:
   10 | constexpr foo::foo(int a) : foo{__trans_tmp_1} {
      |           ^~~
<source>:10:11: internal compiler error: in build_data_member_initialization,
at cp/constexpr.cc:466
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
0xb9a2aa explain_invalid_constexpr_fn(tree_node*)
        ???:0
0xe47f7e store_init_value(tree_node*, tree_node*, vec<tree_node*, va_gc,
vl_embed>**, int)
        ???:0
0xc1e48e cp_finish_decl(tree_node*, tree_node*, bool, tree_node*, int,
cp_decomp*)
        ???: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
```

Reply via email to