When using implicit constexpr, we should not discard the function body, as it
can result in ICE during constant evaluation.
PR c++/123261
gcc/cp/ChangeLog:
* semantics.cc (expand_or_defer_fn_1): Use maybe_constexpr_fn.
gcc/testsuite/ChangeLog:
* g++.dg/ext/fimplicit-constexpr2.C: New test.
the maybe-in-charge cdtor and regenerate the clones from it on
demand, so we also need to keep the body. Otherwise we don't
need it anymore. */
- if (!DECL_DECLARED_CONSTEXPR_P (fn)
+ if (!maybe_constexpr_fn (fn)
&& !(module_maybe_has_cmi_p () && vague_linkage_p (fn)))
DECL_SAVED_TREE (fn) = void_node;
return false;
--- /dev/null
+// { dg-additional-options -fimplicit-constexpr }
+// { dg-do compile { target c++23 } }
+
+class A
+{
+public:
+ A () { asm volatile (""); } // { dg-error {inline assembly is not a constant expression} }
+ ~A () {}
+};
+
+constexpr bool
+test ()
+{
+ A a; // { dg-error {'A::A\(\)' called in a constant expression} }
+ return true;
+}
+
+static_assert (test ()); // { dg-error {non-constant condition for static assertion} }