In r16-57 I thought it was unnecessary to mention incomplete initialization
after another diagnostic, but actually it's useful elaboration.
PR c++/120506
gcc/cp/ChangeLog:
* constexpr.cc (cxx_eval_outermost_constant_expr): Always check
CONSTRUCTOR_NO_CLEARING.
gcc/testsuite/ChangeLog:
* g++.dg/cpp2a/constinit21.C: New test.
/* After verify_constant because reduced_constant_expression_p can unset
CONSTRUCTOR_NO_CLEARING. */
- if (!non_constant_p
- && TREE_CODE (r) == CONSTRUCTOR && CONSTRUCTOR_NO_CLEARING (r))
+ if (TREE_CODE (r) == CONSTRUCTOR && CONSTRUCTOR_NO_CLEARING (r))
{
if (!allow_non_constant)
error ("%qE is not a constant expression because it refers to "
--- /dev/null
+// PR c++/120506
+// { dg-do compile { target c++20 } }
+// Test that we give more information about why the init is non-constant
+
+struct A
+{
+ constexpr A(int c) : counter(c) { }
+
+ int counter;
+};
+
+
+struct B : A
+{
+ constexpr B(int c) : A(c) { }
+
+ int i; // OOPS, not initialized
+};
+
+struct C
+{
+ B sem;
+
+ constexpr C(int c) : sem(c) { }
+};
+
+constinit C s(0); // { dg-error "incompletely initialized" }
+// { dg-prune-output "constant" }