https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97427
--- Comment #2 from CVS Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Marek Polacek <mpola...@gcc.gnu.org>: https://gcc.gnu.org/g:caf17f3afa83623c0f538f6c91c7699c4fdd5674 commit r11-5228-gcaf17f3afa83623c0f538f6c91c7699c4fdd5674 Author: Marek Polacek <pola...@redhat.com> Date: Thu Nov 19 17:56:39 2020 -0500 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.