[Bug c++/100495] constexpr virtual destructor incorrectly reports memory leak

cvs-commit at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Tue Sep 7 17:35:23 GMT 2021


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

--- Comment #7 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:81f9718139cb1cc164ada411ada8cca9f32b8be8

commit r12-3387-g81f9718139cb1cc164ada411ada8cca9f32b8be8
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Tue Sep 7 19:33:28 2021 +0200

    c++: Fix up constexpr evaluation of deleting dtors [PR100495]

    We do not save bodies of constexpr clones and instead evaluate the bodies
    of the constexpr functions they were cloned from.
    I believe that is just fine for constructors because complete vs. base
    ctors differ only in classes that have virtual bases and such constructors
    aren't constexpr, similarly complete/base destructors.
    But as the testcase below shows, for deleting destructors it is not fine,
    deleting dtors while marked as clones in fact are just artificial functions
    with synthetized body which calls the user destructor and deallocation.

    So, either we'd need to evaluate the destructor and afterwards synthetize
    and evaluate the deallocation, or we can just save and use the deleting
    dtors bodies.  The latter seems much easier to me.

    2021-09-07  Jakub Jelinek  <jakub@redhat.com>

            PR c++/100495
            * constexpr.c (maybe_save_constexpr_fundef): Save body even for
            constexpr deleting dtors.
            (cxx_eval_call_expression): Don't use DECL_CLONED_FUNCTION for
            deleting dtors.

            * g++.dg/cpp2a/constexpr-new21.C: New test.


More information about the Gcc-bugs mailing list