public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Marek Polacek <mpolacek@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-7600] c++: Don't allow type-constraint auto(x) [PR104752] Date: Thu, 10 Mar 2022 16:22:59 +0000 (GMT) [thread overview] Message-ID: <20220310162259.88C2F3857C7F@sourceware.org> (raw) https://gcc.gnu.org/g:97f76b5fc4b637033229e53033b4f8b6dc23472c commit r12-7600-g97f76b5fc4b637033229e53033b4f8b6dc23472c Author: Marek Polacek <polacek@redhat.com> Date: Wed Mar 2 12:12:33 2022 -0500 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. Diff: --- gcc/cp/semantics.cc | 8 +++++++- gcc/cp/typeck2.cc | 8 +++++++- gcc/testsuite/g++.dg/cpp23/auto-fncast12.C | 8 ++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 799ce943279..21740064d3d 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%>"); diff --git a/gcc/cp/typeck2.cc b/gcc/cp/typeck2.cc index 39d03e4c3c4..a4c825fc34d 100644 --- a/gcc/cp/typeck2.cc +++ b/gcc/cp/typeck2.cc @@ -2308,7 +2308,13 @@ build_functional_cast_1 (location_t loc, tree exp, tree parms, && list_length (parms) == 1) { init = TREE_VALUE (parms); - if (cxx_dialect < cxx23) + if (is_constrained_auto (anode)) + { + if (complain & tf_error) + error_at (loc, "%<auto(x)%> cannot be constrained"); + return error_mark_node; + } + else if (cxx_dialect < cxx23) pedwarn (loc, OPT_Wc__23_extensions, "%<auto(x)%> only available with " "%<-std=c++2b%> or %<-std=gnu++2b%>"); diff --git a/gcc/testsuite/g++.dg/cpp23/auto-fncast12.C b/gcc/testsuite/g++.dg/cpp23/auto-fncast12.C new file mode 100644 index 00000000000..2856c2846fc --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp23/auto-fncast12.C @@ -0,0 +1,8 @@ +// PR c++/104752 +// { dg-do compile { target c++23 } } + +template<class T> +concept C = true; +auto x = auto(1); // valid (P0849R8) +auto y = C auto(1); // { dg-error "cannot be constrained" } +auto z = C auto{1}; // { dg-error "cannot be constrained" }
reply other threads:[~2022-03-10 16:22 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220310162259.88C2F3857C7F@sourceware.org \ --to=mpolacek@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).