body = fd->body;
else
body = DECL_SAVED_TREE (fun);
- body = massage_constexpr_body (fun, body);
- require_potential_rvalue_constant_expression (body);
+ tree massaged = massage_constexpr_body (fun, body);
+ require_potential_rvalue_constant_expression (massaged);
if (DECL_CONSTRUCTOR_P (fun))
{
- cx_check_missing_mem_inits (DECL_CONTEXT (fun), body, true);
+ cx_check_missing_mem_inits (DECL_CONTEXT (fun), massaged, true);
if (cxx_dialect > cxx11)
- {
- /* Also check the body, not just the ctor-initializer. */
- body = DECL_SAVED_TREE (fun);
- require_potential_rvalue_constant_expression (body);
- }
+ /* Also check the body, not just the ctor-initializer. */
+ require_potential_rvalue_constant_expression (body);
}
}
}
--- /dev/null
+// { dg-do compile { target c++23 } }
+
+struct A { ~A() { } };
+
+struct B {
+ constexpr B() {
+ A a;
+ for (int i = 0; i < 10; i++) { }
+ } // { dg-error "call to non-'constexpr' function 'A::~A..'" }
+};
+
+constexpr bool f() {
+ B b; // { dg-error "B::B..' called in a constant expression" }
+ return true;
+}
+
+static_assert(f()); // { dg-error "non-constant" }