aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/typeck2.c
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2021-11-03 11:04:22 -0400
committerMarek Polacek <polacek@redhat.com>2021-11-18 18:00:08 -0500
commit93810fd673654db9ff16170624a6d36449eab241 (patch)
treef31a7d9ee315aff919b2dd0a393c981dae0e4b54 /gcc/cp/typeck2.c
parent6f4ac4f81f89caac7e74127ed2e6db6bbb3d7426 (diff)
downloadgcc-93810fd673654db9ff16170624a6d36449eab241.zip
gcc-93810fd673654db9ff16170624a6d36449eab241.tar.gz
gcc-93810fd673654db9ff16170624a6d36449eab241.tar.bz2
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.
Diffstat (limited to 'gcc/cp/typeck2.c')
-rw-r--r--gcc/cp/typeck2.c26
1 files changed, 18 insertions, 8 deletions
diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c
index e98fbf7..3fb651a 100644
--- a/gcc/cp/typeck2.c
+++ b/gcc/cp/typeck2.c
@@ -2201,19 +2201,29 @@ build_functional_cast_1 (location_t loc, tree exp, tree parms,
if (tree anode = type_uses_auto (type))
{
- if (!CLASS_PLACEHOLDER_TEMPLATE (anode))
+ tree init;
+ if (CLASS_PLACEHOLDER_TEMPLATE (anode))
+ init = parms;
+ /* C++23 auto(x). */
+ else if (!AUTO_IS_DECLTYPE (anode)
+ && list_length (parms) == 1)
{
- if (complain & tf_error)
- error_at (loc, "invalid use of %qT", anode);
- return error_mark_node;
+ init = TREE_VALUE (parms);
+ if (cxx_dialect < cxx23)
+ pedwarn (loc, OPT_Wc__23_extensions,
+ "%<auto(x)%> only available with "
+ "%<-std=c++2b%> or %<-std=gnu++2b%>");
}
else
{
- type = do_auto_deduction (type, parms, anode, complain,
- adc_variable_type);
- if (type == error_mark_node)
- return error_mark_node;
+ if (complain & tf_error)
+ error_at (loc, "invalid use of %qT", anode);
+ return error_mark_node;
}
+ type = do_auto_deduction (type, init, anode, complain,
+ adc_variable_type);
+ if (type == error_mark_node)
+ return error_mark_node;
}
if (processing_template_decl)