]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: ICE with reference NSDMI [PR114854]
authorMarek Polacek <polacek@redhat.com>
Wed, 8 May 2024 19:43:58 +0000 (15:43 -0400)
committerMarek Polacek <polacek@redhat.com>
Thu, 9 Jan 2025 19:45:27 +0000 (14:45 -0500)
commitda983b32877c86e8fa28027a0e20931527bb437b
tree61d81999ebeecb26dff0c455f0cf000d60e0eee9
parente6dfe71f5a0e43e8c35460d09af16eff93756dfd
c++: ICE with reference NSDMI [PR114854]

Here we crash on a cp_gimplify_expr/TARGET_EXPR assert:

      /* A TARGET_EXPR that expresses direct-initialization should have been
         elided by cp_gimplify_init_expr.  */
      gcc_checking_assert (!TARGET_EXPR_DIRECT_INIT_P (*expr_p));

the TARGET_EXPR in question is created for the NSDMI in:

  class Vector { int m_size; };
  struct S {
    const Vector &vec{};
  };

where we first need to create a Vector{} temporary, and then bind the
vec reference to it.  The temporary is represented by a TARGET_EXPR
and it cannot be elided.  When we create an object of type S, we get

  D.2848 = {.vec=(const struct Vector &) &TARGET_EXPR <D.2840, {.m_size=0}>}

where the TARGET_EXPR is no longer direct-initializing anything.

Fixed by not setting TARGET_EXPR_DIRECT_INIT_P in convert_like_internal/ck_user.

PR c++/114854

gcc/cp/ChangeLog:

* call.cc (convert_like_internal) <case ck_user>: Don't set
TARGET_EXPR_DIRECT_INIT_P.

gcc/testsuite/ChangeLog:

* g++.dg/cpp1y/nsdmi-aggr22.C: New test.

(cherry picked from commit 1a05332bbac98a4c002bef3fb45a3ad9d56b3a71)
gcc/cp/call.cc
gcc/testsuite/g++.dg/cpp1y/nsdmi-aggr22.C [new file with mode: 0644]