https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104213
--- Comment #8 from Marek Polacek <mpolacek at gcc dot gnu.org> --- I've tried diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc index 22d3dd1e2ad..c2a0f0c24e2 100644 --- a/gcc/cp/decl.cc +++ b/gcc/cp/decl.cc @@ -17319,6 +17319,7 @@ finish_constructor_body (void) DECL_RESULT (current_function_decl), val); /* Return the address of the object. */ exprstmt = build_stmt (input_location, RETURN_EXPR, val); + suppress_warning (exprstmt, OPT_Wuse_after_free); add_stmt (exprstmt); } } @@ -17412,6 +17413,7 @@ finish_destructor_body (void) DECL_RESULT (current_function_decl), val); /* Return the address of the object. */ exprstmt = build_stmt (input_location, RETURN_EXPR, val); + suppress_warning (exprstmt, OPT_Wuse_after_free); add_stmt (exprstmt); } } diff --git a/gcc/cp/optimize.cc b/gcc/cp/optimize.cc index 4ad3f1dc9aa..51393710526 100644 --- a/gcc/cp/optimize.cc +++ b/gcc/cp/optimize.cc @@ -168,6 +168,7 @@ build_delete_destructor_body (tree delete_dtor, tree complete_dtor) tree val = DECL_ARGUMENTS (delete_dtor); val = build2 (MODIFY_EXPR, TREE_TYPE (val), DECL_RESULT (delete_dtor), val); + suppress_warning (val, OPT_Wuse_after_free); add_stmt (build_stmt (0, RETURN_EXPR, val)); } } the last hunk should have done the trick but the suppress_warning bits don't survive gimplification, it seems.