https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127386
Bug ID: 127386
Summary: Track which mem-initializers are done during constexpr
construction
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: jakub at gcc dot gnu.org
Target Milestone: ---
The g++.dg/cpp26/within-lifetime3.C testcase has
struct A { int a = 42; bool b = std::is_within_lifetime (&a); };
constexpr A n;
struct B { consteval B () : a (42), b (std::is_within_lifetime (&a)) {} int a;
bool b; };
constexpr B o;
struct C { consteval C () { __builtin_is_within_lifetime (this); } } p;
struct D {
consteval D () : a (0), b (0), c (0) {}
consteval D (int x, int y, int z)
: a (x), b (y + std::is_within_lifetime (&this->a) * 32
+ std::is_within_lifetime (&this->b) * 64
+ std::is_within_lifetime (&this->c) * 128), c (z) {}
constexpr ~D () {}
int a, b, c;
};
consteval int
qux ()
{
D a[2] = {};
std::destroy_at (&a[0]);
std::construct_at (&a[0], 4, 5, 6);
return a[0].a + a[0].b + a[0].c;
}
// FIXME: In mem-initializer of b, a should be already constructed,
// so within lifetime, but b is in the middle of construction and c
// construction has not started yet.
static_assert (qux () == 4 + 5 + 6 + 32); // { dg-bogus "note: the
comparison reduces to '\\\(239 == 47\\\)'" "" { xfail *-*-* } }
// { dg-bogus "static assertion
failed" "" { xfail *-*-* } .-1 }
part xfailed.
For this we need to track which mem-initializer is within lifetime already and
which isn't.