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

            Bug ID: 100368
           Summary: Missing guaranteed elision in constexpr evaluation
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rs2740 at gmail dot com
  Target Milestone: ---

struct S {
  S() = default;
  S(const S&) = delete;
};

struct array {
  S s[2];
};

struct PS {
  constexpr array operator*() const { return {}; }
};

struct W {
  constexpr W(const PS& p)   // 1
    : t(*p) {}
  array t;
};

W w(PS{});

This issues a spurious complaint on trunk and then ICEs:

source>: In constructor 'constexpr W::W(const PS&)':
<source>:17:14: error: use of deleted function 'array::array(array&&)'
   17 |     : t(*p) {}
      |              ^
<source>:7:8: note: 'array::array(array&&)' is implicitly deleted because the
default definition would be ill-formed:
    7 | struct array {
      |        ^~~~~
<source>:7:8: error: use of deleted function 'S::S(S&&)'
<source>:4:3: note: declared here
    4 |   S(S&&) = delete;
      |   ^
<source>:17:14: internal compiler error: tree check: expected target_expr, have
error_mark in bot_manip, at cp/tree.c:3095
   17 |     : t(*p) {}
      |              ^
0x1d002c9 internal_error(char const*, ...)
        ???:0
0x67b4e3 tree_check_failed(tree_node const*, char const*, int, char const*,
...)
        ???:0
0x13967e3 walk_tree_1(tree_node**, tree_node* (*)(tree_node**, int*, void*),
void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*,
tree_node* (*)(tree_node**, int*, tree_node* (*)(tree_node**, int*, void*),
void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*))
        ???:0
0x9ad0ae break_out_target_exprs(tree_node*, bool)
        ???:0
0x72aa0a maybe_save_constexpr_fundef(tree_node*)
        ???:0
0x7b0711 finish_function(bool)
        ???:0
0x8e2c4d c_parse_file()
        ???:0
0xa63232 c_common_parse_file()
        ???:0
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.

Removing the constexpr on the line marked #1 makes it compile. Both clang and
MSVC accept the original code.

Reply via email to