]> git.ipfire.org Git - people/ms/gcc.git/commit
c++: ICE initing lifetime-extended constexpr var [PR107079]
authorMarek Polacek <polacek@redhat.com>
Wed, 8 Feb 2023 19:02:48 +0000 (14:02 -0500)
committerMarek Polacek <polacek@redhat.com>
Tue, 7 Mar 2023 16:23:33 +0000 (11:23 -0500)
commitfb82334341e21ad0254f63e942be276f62d111cf
treeca013afcd27e9786e4674523cf61e56173a5a064
parent19ed6bf44c3fec882cf4c825f3ffa4f2ecdc78e6
c++: ICE initing lifetime-extended constexpr var [PR107079]

We ICE on the simple:

  struct X { const X* x = this; };
  constexpr const X& x = X{};

where store_init_value initializes 'x' with

  &TARGET_EXPR <D.2768, {.x=(const struct X *) &<PLACEHOLDER_EXPR struct X>}>

but we must lifetime-extend via extend_ref_init_temps and we get

  _ZGR1x_.x = (const struct X *) &<PLACEHOLDER_EXPR struct X> >>>;, (const struct X &) &_ZGR1x_;

Since 'x' was declared constexpr, we do cxx_constant_init and we hit
the preeval code added in r269003 while evaluating the INIT_EXPR:

  _ZGR1x_.x = (const struct X *) &<PLACEHOLDER_EXPR struct X> >>>

but we have no ctx.ctor or ctx.object here so lookup_placeholder won't
find anything that could replace X and we ICE on
 7861       /* A placeholder without a referent.  We can get here when
 7862          checking whether NSDMIs are noexcept, or in massage_init_elt;
 7863          just say it's non-constant for now.  */
 7864       gcc_assert (ctx->quiet);
because cxx_constant_init means !ctx->quiet.  It's not correct that
there isn't a referent.  I think the following patch is a pretty
straightforward fix: pass the _ZGR var down to maybe_constant_init so
that it can replace the PLACEHOLDER_EXPR with _ZGR1x_.

The commented assert in the test doesn't pass: we complain that _ZGR1x_
isn't a constexpr variable because we don't implement DR2126 (PR101588).

PR c++/107079

gcc/cp/ChangeLog:

* call.cc (set_up_extended_ref_temp): Pass var to maybe_constant_init.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/constexpr-nsdmi2.C: New test.

(cherry picked from commit 67b82bc1b29b82e4577df9491793624f3a8eb12f)
gcc/cp/call.cc
gcc/testsuite/g++.dg/cpp0x/constexpr-nsdmi2.C [new file with mode: 0644]