From: Marek Polacek <polacek@redhat.com>
To: GCC Patches <gcc-patches@gcc.gnu.org>, Jason Merrill <jason@redhat.com>
Subject: [PATCH] c++: ->template and implicit typedef [PR104608]
Date: Tue, 22 Feb 2022 16:46:17 -0500 [thread overview]
Message-ID: <20220222214617.1949703-1-polacek@redhat.com> (raw)
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
next reply other threads:[~2022-02-22 21:46 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-22 21:46 Marek Polacek [this message]
2022-02-28 16:31 ` Jason Merrill
2022-03-01 21:12 ` [PATCH v2] " Marek Polacek
2022-03-10 4:14 ` Jason Merrill
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=20220222214617.1949703-1-polacek@redhat.com \
--to=polacek@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jason@redhat.com \
/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).