c++: Implement C++23 P0849R8 - auto(x) [PR103049]
authorMarek Polacek <polacek@redhat.com>
Wed, 3 Nov 2021 15:04:22 +0000 (11:04 -0400)
committerMarek Polacek <polacek@redhat.com>
Thu, 18 Nov 2021 23:00:08 +0000 (18:00 -0500)
commit93810fd673654db9ff16170624a6d36449eab241
treef31a7d9ee315aff919b2dd0a393c981dae0e4b54
parent6f4ac4f81f89caac7e74127ed2e6db6bbb3d7426
c++: Implement C++23 P0849R8 - auto(x) [PR103049]

This patch implements P0849R8 which allows auto in a functional cast,
the result of which is a prvalue.

[expr.type.conv]/1 says that the type is determined by placeholder type
deduction.  We only accept 'auto', not 'decltype(auto)' -- that the
type shall be auto comes from [dcl.type.auto.deduct].  Therefore the
rules are like for [temp.deduct.call], deducing template arguments from
a function call, so the result type will never be a reference, and we
decay arrays/functions.

PR c++/103049

gcc/cp/ChangeLog:

* semantics.c (finish_compound_literal): Accept C++23 auto{x}.
* typeck2.c (build_functional_cast_1): Accept C++23 auto(x).

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/auto25.C: Adjust dg-error.
* g++.dg/cpp0x/auto9.C: Likewise.
* g++.dg/cpp2a/concepts-pr84979-2.C: Likewise.
* g++.dg/cpp2a/concepts-pr84979-3.C: Likewise.
* g++.dg/cpp23/auto-fncast1.C: New test.
* g++.dg/cpp23/auto-fncast2.C: New test.
* g++.dg/cpp23/auto-fncast3.C: New test.
* g++.dg/cpp23/auto-fncast4.C: New test.
* g++.dg/cpp23/auto-fncast5.C: New test.
* g++.dg/cpp23/auto-fncast6.C: New test.
12 files changed:
gcc/cp/semantics.c
gcc/cp/typeck2.c
gcc/testsuite/g++.dg/cpp0x/auto25.C
gcc/testsuite/g++.dg/cpp0x/auto9.C
gcc/testsuite/g++.dg/cpp23/auto-fncast1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp23/auto-fncast2.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp23/auto-fncast3.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp23/auto-fncast4.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp23/auto-fncast5.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp23/auto-fncast6.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/concepts-pr84979-2.C
gcc/testsuite/g++.dg/cpp2a/concepts-pr84979-3.C