c++: Fix wrong error with constexpr destructor [PR97427]
When I implemented the code to detect modifying const objects in constexpr contexts, we couldn't have constexpr destructors, so I didn't consider them. But now we can and that caused a bogus error in this testcase: [class.dtor]p5 says that "const and volatile semantics are not applied on an object under destruction. They stop being in effect when the destructor for the most derived object starts." so we have to clear the TREE_READONLY flag we set on the object after the constructors have been called to mark it as no-longer-under-construction. In the ~Foo call it's now an object under destruction, so don't report those errors. gcc/cp/ChangeLog: PR c++/97427 * constexpr.c (cxx_set_object_constness): New function. (cxx_eval_call_expression): Set new_obj for destructors too. Call cxx_set_object_constness to set/unset TREE_READONLY of the object under construction/destruction. gcc/testsuite/ChangeLog: PR c++/97427 * g++.dg/cpp2a/constexpr-dtor10.C: New test.
Loading
Please register or sign in to comment