From 93810fd673654db9ff16170624a6d36449eab241 Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Wed, 3 Nov 2021 11:04:22 -0400 Subject: 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. --- gcc/cp/semantics.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'gcc/cp/semantics.c') diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 8f79f04..d962b29 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -3134,6 +3134,20 @@ finish_compound_literal (tree type, tree compound_literal, if (type == error_mark_node) return error_mark_node; } + /* C++23 auto{x}. */ + else if (is_auto (type) + && !AUTO_IS_DECLTYPE (type) + && CONSTRUCTOR_NELTS (compound_literal) == 1) + { + if (cxx_dialect < cxx23) + pedwarn (input_location, OPT_Wc__23_extensions, + "% only available with " + "%<-std=c++2b%> or %<-std=gnu++2b%>"); + type = do_auto_deduction (type, compound_literal, type, complain, + adc_variable_type); + if (type == error_mark_node) + return error_mark_node; + } /* Used to hold a copy of the compound literal in a template. */ tree orig_cl = NULL_TREE; -- cgit v1.1