aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2022-02-22 15:03:34 -0500
committerMarek Polacek <polacek@redhat.com>2022-03-10 11:23:41 -0500
commit4602a494e94835f693a9230adb69ce92249ebf15 (patch)
tree54c5d3c41f14ff1e75bfa7acee6bfb093e728343 /gcc
parent97f76b5fc4b637033229e53033b4f8b6dc23472c (diff)
downloadgcc-4602a494e94835f693a9230adb69ce92249ebf15.zip
gcc-4602a494e94835f693a9230adb69ce92249ebf15.tar.gz
gcc-4602a494e94835f693a9230adb69ce92249ebf15.tar.bz2
c++: ->template and implicit typedef [PR104608]
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 TYPE_DECLs that cp_parser_template_id can't handle, a la r12-6879. PR c++/104608 gcc/cp/ChangeLog: * parser.cc (cp_parser_template_name): Repeat lookup of TYPE_DECLs. gcc/testsuite/ChangeLog: * g++.dg/parse/template-keyword3.C: New test. * g++.dg/parse/template-keyword4.C: New test.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/parser.cc5
-rw-r--r--gcc/testsuite/g++.dg/parse/template-keyword3.C12
-rw-r--r--gcc/testsuite/g++.dg/parse/template-keyword4.C17
3 files changed, 33 insertions, 1 deletions
diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index 18db9d4..87b9781 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -18674,7 +18674,10 @@ 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
+ /* cp_parser_template_id can only handle some TYPE_DECLs. */
+ || (TREE_CODE (decl) == TYPE_DECL
+ && TREE_CODE (TREE_TYPE (decl)) != TYPENAME_TYPE))
/* 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 0000000..59fe0fc
--- /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>();
+}
diff --git a/gcc/testsuite/g++.dg/parse/template-keyword4.C b/gcc/testsuite/g++.dg/parse/template-keyword4.C
new file mode 100644
index 0000000..c688094
--- /dev/null
+++ b/gcc/testsuite/g++.dg/parse/template-keyword4.C
@@ -0,0 +1,17 @@
+// PR c++/104608
+// { dg-do compile { target c++11 } }
+
+class S;
+using Parameter = S;
+typedef S Parameter2;
+
+template <typename R> class Function
+: public R
+{
+ Function();
+};
+template <typename R>
+Function<R>::Function() {
+ this->template Parameter<R>();
+ this->template Parameter2<R>();
+}