Since r16-3022, 20_util/variant/102912.cc was failing in C++20 and above due
to wrong errors about destruction modifying a const object; destruction is
OK.
PR c++/121068
gcc/cp/ChangeLog:
* constexpr.cc (cxx_eval_store_expression): Allow clobber of a const
object.
gcc/testsuite/ChangeLog:
* g++.dg/cpp2a/constexpr-dtor18.C: New test.
ctx->global->destroy_value (object);
return void_node;
}
+
+ /* Ending the lifetime of a const object is OK. */
+ const_object_being_modified = NULL_TREE;
}
type = TREE_TYPE (object);
--- /dev/null
+// PR c++/121068
+// { dg-do compile { target c++20 } }
+
+template <class T>
+constexpr void
+destroy_at (T* p) { p->~T(); }
+
+template <class T>
+struct V {
+ union {
+ unsigned char buf[sizeof (T)];
+ const T ct;
+ };
+ bool active;
+ constexpr V(): active (false) {}
+ constexpr V(T t): ct (t), active (true) { }
+ constexpr ~V() { if (active) destroy_at (&ct); }
+};
+
+constexpr char f()
+{
+ const V<int> vi {42};
+ return vi.ct;
+}
+
+static_assert (f() == 42);