Files
gcc-reflection/gcc/testsuite/g++.dg/cpp1z/constexpr-lambda27.C
Jason Merrill 9efe4e153d c++: constexpr, empty base after non-empty [PR106369]
Here the CONSTRUCTOR we were providing for D{} had an entry for the B base
subobject at offset 0 following the entry for the C base, causing
output_constructor_regular_field to ICE due to going backwards.  It might be
nice for that function to be more tolerant of empty fields, but it also
seems reasonable for the front end to prune the useless entry.

	PR c++/106369

gcc/cp/ChangeLog:

	* constexpr.cc (reduced_constant_expression_p): Return false
	if a CONSTRUCTOR initializes an empty field.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp1z/constexpr-lambda27.C: New test.
2022-07-30 19:56:36 -07:00

27 lines
675 B
C

// PR c++/106369
// { dg-do compile { target c++17 } }
struct A {
int a[256];
constexpr int &operator[] (int n) noexcept { return a[n]; }
constexpr const int &operator[] (int n) const noexcept { return a[n]; }
};
struct B {};
template <typename T>
struct C {
constexpr T &foo (const char x) noexcept { c = T::d[x]; return static_cast<T &>(*this); }
int c;
};
struct D : public C<D>, public B
{
D () noexcept = default;
static constexpr char e[9] { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I' };
static constexpr A d = [] () constexpr {
A f {};
for (int i = 0; i < 9; ++i)
f[e[i]] = 1;
return f;
} ();
};
constexpr auto g = D{}.foo ('E');