aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/semantics.cc
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2022-03-02 12:12:33 -0500
committerMarek Polacek <polacek@redhat.com>2022-03-10 11:22:40 -0500
commit97f76b5fc4b637033229e53033b4f8b6dc23472c (patch)
tree55f2a369772fc52fbba7886a31818f2639c7114b /gcc/cp/semantics.cc
parentac8310dd122172bf9d7217e3367da55f9bf9b21b (diff)
downloadgcc-97f76b5fc4b637033229e53033b4f8b6dc23472c.zip
gcc-97f76b5fc4b637033229e53033b4f8b6dc23472c.tar.gz
gcc-97f76b5fc4b637033229e53033b4f8b6dc23472c.tar.bz2
c++: Don't allow type-constraint auto(x) [PR104752]
104752 points out that template<class T> concept C = true; auto y = C auto(1); is ill-formed as per [dcl.type.auto.deduct]: "For an explicit type conversion, T is the specified type, which shall be auto." which doesn't allow type-constraint auto. PR c++/104752 gcc/cp/ChangeLog: * semantics.cc (finish_compound_literal): Disallow auto{x} for is_constrained_auto. * typeck2.cc (build_functional_cast_1): Likewise. gcc/testsuite/ChangeLog: * g++.dg/cpp23/auto-fncast12.C: New test.
Diffstat (limited to 'gcc/cp/semantics.cc')
-rw-r--r--gcc/cp/semantics.cc8
1 files changed, 7 insertions, 1 deletions
diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
index 799ce94..2174006 100644
--- a/gcc/cp/semantics.cc
+++ b/gcc/cp/semantics.cc
@@ -3150,7 +3150,13 @@ finish_compound_literal (tree type, tree compound_literal,
&& !AUTO_IS_DECLTYPE (type)
&& CONSTRUCTOR_NELTS (compound_literal) == 1)
{
- if (cxx_dialect < cxx23)
+ if (is_constrained_auto (type))
+ {
+ if (complain & tf_error)
+ error ("%<auto{x}%> cannot be constrained");
+ return error_mark_node;
+ }
+ else if (cxx_dialect < cxx23)
pedwarn (input_location, OPT_Wc__23_extensions,
"%<auto{x}%> only available with "
"%<-std=c++2b%> or %<-std=gnu++2b%>");