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

--- Comment #9 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jason Merrill <ja...@gcc.gnu.org>:

https://gcc.gnu.org/g:7c82dd6c02d44d9d2cd84dda137c00b1a3cd6c90

commit r10-5926-g7c82dd6c02d44d9d2cd84dda137c00b1a3cd6c90
Author: Jason Merrill <ja...@redhat.com>
Date:   Fri Jan 10 17:14:12 2020 -0500

    PR c++/33799 - destroy return value if local cleanup throws.

    This is a pretty rare situation since the C++11 change to make all
    destructors default to noexcept, but it is still possible to define
throwing
    destructors, and if a destructor for a local variable throws during the
    return, we've already constructed the return value, so now we need to
    destroy it.  I handled this somewhat like the new-expression cleanup; as in
    that case, this cleanup can't properly nest with the cleanups for local
    variables, so I introduce a cleanup region around the whole function and a
    flag variable to indicate whether the return value actually needs to be
    destroyed.

    Setting the flag requires giving a COMPOUND_EXPR as the operand of a
    RETURN_EXPR, so I adjust gimplify_return_expr to handle that.

    This doesn't currently work with deduced return type because we don't know
    the type when we're deciding whether to introduce the cleanup region.

    gcc/
        * gimplify.c (gimplify_return_expr): Handle COMPOUND_EXPR.
    gcc/cp/
        * cp-tree.h (current_retval_sentinel): New macro.
        * decl.c (start_preparsed_function): Set up cleanup for retval.
        * typeck.c (check_return_expr): Set current_retval_sentinel.

Reply via email to