public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] c++: ->template and implicit typedef [PR104608]
@ 2022-02-22 21:46 Marek Polacek
  2022-02-28 16:31 ` Jason Merrill
  0 siblings, 1 reply; 4+ messages in thread
From: Marek Polacek @ 2022-02-22 21:46 UTC (permalink / raw)
  To: GCC Patches, Jason Merrill

Here we have a forward declaration of Parameter for which we create
an implicit typedef, which is a TYPE_DECL.  Then, when looking it up
at template definition time, cp_parser_template_id gets (since r12-6754)
this TYPE_DECL which it can't handle.

This patch defers lookup for implicit typedefs, a la r12-6879.

Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?

	PR c++/104608

gcc/cp/ChangeLog:

	* parser.cc (cp_parser_template_name): Repeat lookup of implicit
	typedef.

gcc/testsuite/ChangeLog:

	* g++.dg/parse/template-keyword3.C: New test.
---
 gcc/cp/parser.cc                               |  3 ++-
 gcc/testsuite/g++.dg/parse/template-keyword3.C | 12 ++++++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/parse/template-keyword3.C

diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index 03d99aba13e..5e89e3737b0 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -18681,7 +18681,8 @@ cp_parser_template_name (cp_parser* parser,
 	  return error_mark_node;
 	}
       else if ((!DECL_P (decl) && !is_overloaded_fn (decl))
-	       || TREE_CODE (decl) == USING_DECL)
+	       || TREE_CODE (decl) == USING_DECL
+	       || DECL_IMPLICIT_TYPEDEF_P (decl))
 	/* Repeat the lookup at instantiation time.  */
 	decl = identifier;
     }
diff --git a/gcc/testsuite/g++.dg/parse/template-keyword3.C b/gcc/testsuite/g++.dg/parse/template-keyword3.C
new file mode 100644
index 00000000000..59fe0fc180b
--- /dev/null
+++ b/gcc/testsuite/g++.dg/parse/template-keyword3.C
@@ -0,0 +1,12 @@
+// PR c++/104608
+
+class Parameter;
+template <typename R> class Function 
+: public R  
+{
+    Function();
+};
+template <typename R>
+Function<R>::Function() {
+    this->template Parameter<R>();
+}

base-commit: bc66b471d16ef2fd8cb66fd1131b41f80ecb9961
-- 
2.35.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-03-10  4:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-22 21:46 [PATCH] c++: ->template and implicit typedef [PR104608] Marek Polacek
2022-02-28 16:31 ` Jason Merrill
2022-03-01 21:12   ` [PATCH v2] " Marek Polacek
2022-03-10  4:14     ` Jason Merrill

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