From 305a2686c99bf9b57490419f25c79f6fb3ae0feb Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Tue, 28 Nov 2023 13:54:47 -0500 Subject: c++: prvalue array decay [PR94264] My change for PR53220 made array to pointer decay for prvalue arrays ill-formed to catch well-defined C code that produces a dangling pointer in C++ due to the shorter lifetime of compound literals. This wasn't really correct, but wasn't a problem until C++17 added prvalue arrays, at which point it started rejecting valid C++ code. I wanted to make sure that we still diagnose the problematic code; -Wdangling-pointer covers the array-lit.c case, but I needed to extend -Wreturn-local-addr to handle the return case. PR c++/94264 PR c++/53220 gcc/c/ChangeLog: * c-typeck.cc (array_to_pointer_conversion): Adjust -Wc++-compat diagnostic. gcc/cp/ChangeLog: * call.cc (convert_like_internal): Remove obsolete comment. * typeck.cc (decay_conversion): Allow array prvalue. (maybe_warn_about_returning_address_of_local): Check for returning pointer to temporary. gcc/testsuite/ChangeLog: * c-c++-common/array-lit.c: Adjust. * g++.dg/cpp1z/array-prvalue1.C: New test. * g++.dg/ext/complit17.C: New test. --- gcc/c/c-typeck.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gcc/c') diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc index 1dbb447..17fdc97 100644 --- a/gcc/c/c-typeck.cc +++ b/gcc/c/c-typeck.cc @@ -1748,7 +1748,7 @@ array_to_pointer_conversion (location_t loc, tree exp) if (!TREE_READONLY (decl) && !TREE_STATIC (decl)) warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wc___compat, "converting an array compound literal to a pointer " - "is ill-formed in C++"); + "leads to a dangling pointer in C++"); } adr = build_unary_op (loc, ADDR_EXPR, exp, true); -- cgit v1.1