diff options
author | Jason Merrill <jason@redhat.com> | 2023-11-28 13:54:47 -0500 |
---|---|---|
committer | Jason Merrill <jason@redhat.com> | 2023-11-28 16:29:19 -0500 |
commit | 305a2686c99bf9b57490419f25c79f6fb3ae0feb (patch) | |
tree | d6002e2cc5253350245349cd3d8e19767cd72d6e /gcc/c/c-typeck.cc | |
parent | 3d104d93a7011146b0870ab160613147adb8d9b3 (diff) | |
download | gcc-305a2686c99bf9b57490419f25c79f6fb3ae0feb.zip gcc-305a2686c99bf9b57490419f25c79f6fb3ae0feb.tar.gz gcc-305a2686c99bf9b57490419f25c79f6fb3ae0feb.tar.bz2 |
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.
Diffstat (limited to 'gcc/c/c-typeck.cc')
-rw-r--r-- | gcc/c/c-typeck.cc | 2 |
1 files changed, 1 insertions, 1 deletions
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); |