[Bug c++/97427] constexpr destructor for const object incorrectly rejected as modifying const object

cvs-commit at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Tue Jan 5 21:29:14 GMT 2021


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97427

--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-10 branch has been updated by Marek Polacek
<mpolacek@gcc.gnu.org>:

https://gcc.gnu.org/g:4a8a0d38b128d36a0cf1ac6a7879307b937418ee

commit r10-9204-g4a8a0d38b128d36a0cf1ac6a7879307b937418ee
Author: Marek Polacek <polacek@redhat.com>
Date:   Tue Jan 5 16:27:30 2021 -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.


More information about the Gcc-bugs mailing list