public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-99] c++: Hard error with tentative parse and CTAD [PR87709]
@ 2021-04-24  4:14 Patrick Palka
  0 siblings, 0 replies; only message in thread
From: Patrick Palka @ 2021-04-24  4:14 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:5f1a2cb9c2dc09eed53da5d5787d14bec700b10b

commit r12-99-g5f1a2cb9c2dc09eed53da5d5787d14bec700b10b
Author: Patrick Palka <ppalka@redhat.com>
Date:   Sat Apr 24 00:01:42 2021 -0400

    c++: Hard error with tentative parse and CTAD [PR87709]
    
    When parsing e.g. the operand of sizeof, where both types and
    expressions are accepted, if during the tentative type parse we
    encounter an unexpected template placeholder, we must simulate
    an error rather than issue a real error because the expression
    parse can still succeed.
    
    gcc/cp/ChangeLog:
    
            PR c++/87709
            * parser.c (cp_parser_type_id_1): If we see a template
            placeholder, first try simulating an error before issuing
            a real error.
    
    gcc/testsuite/ChangeLog:
    
            PR c++/87709
            * g++.dg/cpp1z/class-deduction86.C: New test.

Diff:
---
 gcc/cp/parser.c                                | 11 +++++++----
 gcc/testsuite/g++.dg/cpp1z/class-deduction86.C | 16 ++++++++++++++++
 2 files changed, 23 insertions(+), 4 deletions(-)

diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index fba516efa23..e1b1617da68 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -23270,10 +23270,13 @@ cp_parser_type_id_1 (cp_parser *parser, cp_parser_flags flags,
 	    location_t loc = type_specifier_seq.locations[ds_type_spec];
 	    if (tree tmpl = CLASS_PLACEHOLDER_TEMPLATE (auto_node))
 	      {
-		error_at (loc, "missing template arguments after %qT",
-			  auto_node);
-		inform (DECL_SOURCE_LOCATION (tmpl), "%qD declared here",
-			tmpl);
+		if (!cp_parser_simulate_error (parser))
+		  {
+		    error_at (loc, "missing template arguments after %qT",
+			      auto_node);
+		    inform (DECL_SOURCE_LOCATION (tmpl), "%qD declared here",
+			    tmpl);
+		  }
 	      }
 	    else if (parser->in_template_argument_list_p)
 	      error_at (loc, "%qT not permitted in template argument",
diff --git a/gcc/testsuite/g++.dg/cpp1z/class-deduction86.C b/gcc/testsuite/g++.dg/cpp1z/class-deduction86.C
new file mode 100644
index 00000000000..a198ed24ec6
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1z/class-deduction86.C
@@ -0,0 +1,16 @@
+// PR c++/87709
+// { dg-do compile { target c++17 } }
+
+template <class T>
+struct lit {
+  lit(T) { }
+};
+
+template <class T>
+int operator+(lit<T>, lit<T>) {
+  return 0;
+}
+
+auto r2 = (lit(0)) + lit(0);
+
+static_assert(sizeof(lit(0)));


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-04-24  4:14 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-24  4:14 [gcc r12-99] c++: Hard error with tentative parse and CTAD [PR87709] Patrick Palka

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).