From: Jason Merrill <jason@redhat.com>
To: gcc-patches@gcc.gnu.org
Subject: [pushed] c++: diagnose auto in template arg
Date: Fri, 9 Jun 2023 11:41:03 -0400 [thread overview]
Message-ID: <20230609154103.3386960-1-jason@redhat.com> (raw)
Tested x86_64-pc-linux-gnu, applying to trunk.
-- 8< --
We were failing to diagnose this Concepts TS feature that didn't make it
into C++20 because the 'auto' was getting converted to a template parameter
before we checked for it. So also check in cp_parser_simple_type_specifier.
The code in cp_parser_template_type_arg that I initially expected to
diagnose this seems unreachable because cp_parser_type_id_1 already checks
auto.
gcc/cp/ChangeLog:
* parser.cc (cp_parser_simple_type_specifier): Check for auto
in template argument.
(cp_parser_template_type_arg): Remove auto checking.
gcc/testsuite/ChangeLog:
* g++.dg/concepts/auto7.C: New test.
* g++.dg/concepts/auto7a.C: New test.
---
gcc/cp/parser.cc | 17 ++++++++---------
gcc/testsuite/g++.dg/concepts/auto7.C | 9 +++++++++
gcc/testsuite/g++.dg/concepts/auto7a.C | 8 ++++++++
3 files changed, 25 insertions(+), 9 deletions(-)
create mode 100644 gcc/testsuite/g++.dg/concepts/auto7.C
create mode 100644 gcc/testsuite/g++.dg/concepts/auto7a.C
diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index d77fbd20e56..09cba713437 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -19823,15 +19823,19 @@ cp_parser_simple_type_specifier (cp_parser* parser,
"only available with "
"%<-std=c++14%> or %<-std=gnu++14%>");
}
+ else if (!flag_concepts_ts && parser->in_template_argument_list_p)
+ pedwarn (token->location, 0,
+ "use of %<auto%> in template argument "
+ "only available with %<-fconcepts-ts%>");
+ else if (!flag_concepts)
+ pedwarn (token->location, 0,
+ "use of %<auto%> in parameter declaration "
+ "only available with %<-std=c++20%> or %<-fconcepts%>");
else if (cxx_dialect < cxx14)
error_at (token->location,
"use of %<auto%> in parameter declaration "
"only available with "
"%<-std=c++14%> or %<-std=gnu++14%>");
- else if (!flag_concepts)
- pedwarn (token->location, 0,
- "use of %<auto%> in parameter declaration "
- "only available with %<-std=c++20%> or %<-fconcepts%>");
}
else
type = make_auto ();
@@ -24522,11 +24526,6 @@ cp_parser_template_type_arg (cp_parser *parser)
= G_("types may not be defined in template arguments");
r = cp_parser_type_id_1 (parser, CP_PARSER_FLAGS_NONE, true, false, NULL);
parser->type_definition_forbidden_message = saved_message;
- if (cxx_dialect >= cxx14 && !flag_concepts && type_uses_auto (r))
- {
- error ("invalid use of %<auto%> in template argument");
- r = error_mark_node;
- }
return r;
}
diff --git a/gcc/testsuite/g++.dg/concepts/auto7.C b/gcc/testsuite/g++.dg/concepts/auto7.C
new file mode 100644
index 00000000000..3cbf5dd8dfc
--- /dev/null
+++ b/gcc/testsuite/g++.dg/concepts/auto7.C
@@ -0,0 +1,9 @@
+// { dg-do compile { target c++14 } }
+// { dg-additional-options -fconcepts-ts }
+
+template <class T> struct A { };
+void f(A<auto> a) { }
+int main()
+{
+ f(A<int>());
+}
diff --git a/gcc/testsuite/g++.dg/concepts/auto7a.C b/gcc/testsuite/g++.dg/concepts/auto7a.C
new file mode 100644
index 00000000000..88868f45d1c
--- /dev/null
+++ b/gcc/testsuite/g++.dg/concepts/auto7a.C
@@ -0,0 +1,8 @@
+// { dg-do compile { target c++14 } }
+
+template <class T> struct A { };
+void f(A<auto> a) { } // { dg-error "auto. in template argument" }
+int main()
+{
+ f(A<int>());
+}
base-commit: 3e12669a0eb968cfcbe9242b382fd8020935edf8
--
2.31.1
reply other threads:[~2023-06-09 15:41 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=20230609154103.3386960-1-jason@redhat.com \
--to=jason@redhat.com \
--cc=gcc-patches@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: link
Be 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).