From: Adam Butcher <adam@jessamine.co.uk>
To: Jason Merrill <jason@redhat.com>,
Paolo Carlini <paolo.carlini@oracle.com>
Cc: gcc-patches@gcc.gnu.org,
Alexander Adam <alexander.adam@informatik.tu-chemnitz.de>,
Jonathan Wakely <redi@gcc.gnu.org>,
Adam Butcher <adam@jessamine.co.uk>
Subject: Re: [PATCH] Fix PR c++/61537
Date: Wed, 25 Jun 2014 20:05:00 -0000 [thread overview]
Message-ID: <1403666183-13009-1-git-send-email-adam@jessamine.co.uk> (raw)
In-Reply-To: <53AAC4B2.3040905@redhat.com>
* parser.c (cp_parser_elaborated_type_specifier): Only consider template
parameter lists outside of function parameter scope.
* g++.dg/template/pr61537.C: New testcase.
---
gcc/cp/parser.c | 31 ++++++++++++++++++++++---------
gcc/testsuite/g++.dg/template/pr61537.C | 23 +++++++++++++++++++++++
2 files changed, 45 insertions(+), 9 deletions(-)
create mode 100644 gcc/testsuite/g++.dg/template/pr61537.C
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 41200a0..c440c99 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -15081,6 +15081,18 @@ cp_parser_elaborated_type_specifier (cp_parser* parser,
return cp_parser_make_typename_type (parser, parser->scope,
identifier,
token->location);
+
+ /* Template parameter lists apply only if we are not within a
+ function parameter list. */
+ bool template_parm_lists_apply
+ = parser->num_template_parameter_lists;
+ if (template_parm_lists_apply)
+ for (cp_binding_level *s = current_binding_level;
+ s && s->kind != sk_template_parms;
+ s = s->level_chain)
+ if (s->kind == sk_function_parms)
+ template_parm_lists_apply = false;
+
/* Look up a qualified name in the usual way. */
if (parser->scope)
{
@@ -15123,7 +15135,7 @@ cp_parser_elaborated_type_specifier (cp_parser* parser,
decl = (cp_parser_maybe_treat_template_as_class
(decl, /*tag_name_p=*/is_friend
- && parser->num_template_parameter_lists));
+ && template_parm_lists_apply));
if (TREE_CODE (decl) != TYPE_DECL)
{
@@ -15136,9 +15148,9 @@ cp_parser_elaborated_type_specifier (cp_parser* parser,
if (TREE_CODE (TREE_TYPE (decl)) != TYPENAME_TYPE)
{
- bool allow_template = (parser->num_template_parameter_lists
- || DECL_SELF_REFERENCE_P (decl));
- type = check_elaborated_type_specifier (tag_type, decl,
+ bool allow_template = (template_parm_lists_apply
+ || DECL_SELF_REFERENCE_P (decl));
+ type = check_elaborated_type_specifier (tag_type, decl,
allow_template);
if (type == error_mark_node)
@@ -15224,15 +15236,16 @@ cp_parser_elaborated_type_specifier (cp_parser* parser,
ts = ts_global;
template_p =
- (parser->num_template_parameter_lists
+ (template_parm_lists_apply
&& (cp_parser_next_token_starts_class_definition_p (parser)
|| cp_lexer_next_token_is (parser->lexer, CPP_SEMICOLON)));
/* An unqualified name was used to reference this type, so
there were no qualifying templates. */
- if (!cp_parser_check_template_parameters (parser,
- /*num_templates=*/0,
- token->location,
- /*declarator=*/NULL))
+ if (template_parm_lists_apply
+ && !cp_parser_check_template_parameters (parser,
+ /*num_templates=*/0,
+ token->location,
+ /*declarator=*/NULL))
return error_mark_node;
type = xref_tag (tag_type, identifier, ts, template_p);
}
diff --git a/gcc/testsuite/g++.dg/template/pr61537.C b/gcc/testsuite/g++.dg/template/pr61537.C
new file mode 100644
index 0000000..12aaf58
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/pr61537.C
@@ -0,0 +1,23 @@
+// PR c++/61537
+// { dg-do compile }
+
+struct A {};
+
+template <typename T>
+struct B
+{
+ template <typename U>
+ void f(U, struct A);
+};
+
+template <typename T>
+template <typename U>
+void B<T>::f(U, struct A)
+{
+}
+
+int main()
+{
+ B<char> b;
+ b.f(42, A());
+}
--
2.0.0
next prev parent reply other threads:[~2014-06-25 20:05 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-24 21:08 Adam Butcher
2014-06-24 22:25 ` Paolo Carlini
2014-06-24 23:05 ` Adam Butcher
2014-06-25 12:46 ` Jason Merrill
2014-06-25 20:05 ` Adam Butcher [this message]
2014-06-25 20:57 ` Jason Merrill
2014-06-26 5:08 ` Adam Butcher
2014-06-26 16:16 ` 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=1403666183-13009-1-git-send-email-adam@jessamine.co.uk \
--to=adam@jessamine.co.uk \
--cc=alexander.adam@informatik.tu-chemnitz.de \
--cc=gcc-patches@gcc.gnu.org \
--cc=jason@redhat.com \
--cc=paolo.carlini@oracle.com \
--cc=redi@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).