public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fix PR c++/61537
@ 2014-06-24 21:08 Adam Butcher
  2014-06-24 22:25 ` Paolo Carlini
  0 siblings, 1 reply; 8+ messages in thread
From: Adam Butcher @ 2014-06-24 21:08 UTC (permalink / raw)
  To: gcc-patches
  Cc: Jason Merrill, Alexander Adam, Jonathan Wakely, Paolo Carlini,
	Adam Butcher

	* parser.c (cp_parser_elaborated_type_specifier): Only consider template
	parameter lists outside of function parameter scope.

	* g++.dg/cpp1y/pr61537.C: New testcase.
---
 gcc/cp/parser.c                      | 28 +++++++++++++++++++---------
 gcc/testsuite/g++.dg/cpp1y/pr61537.C | 24 ++++++++++++++++++++++++
 2 files changed, 43 insertions(+), 9 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp1y/pr61537.C

diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 41200a0..736d012 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -15081,6 +15081,15 @@ 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;
+      for (cp_binding_level *s = current_binding_level; s; 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 +15132,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 +15145,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 +15233,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/cpp1y/pr61537.C b/gcc/testsuite/g++.dg/cpp1y/pr61537.C
new file mode 100644
index 0000000..55761cd
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/pr61537.C
@@ -0,0 +1,24 @@
+// PR c++/61537
+// { dg-do compile { target c++1y } }
+// { dg-options "" }
+
+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

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

* Re: [PATCH] Fix PR c++/61537
  2014-06-24 21:08 [PATCH] Fix PR c++/61537 Adam Butcher
@ 2014-06-24 22:25 ` Paolo Carlini
  2014-06-24 23:05   ` Adam Butcher
  0 siblings, 1 reply; 8+ messages in thread
From: Paolo Carlini @ 2014-06-24 22:25 UTC (permalink / raw)
  To: Adam Butcher, gcc-patches; +Cc: Jason Merrill, Alexander Adam, Jonathan Wakely

Hi,

On 06/24/2014 01:40 AM, Adam Butcher wrote:
> +++ b/gcc/testsuite/g++.dg/cpp1y/pr61537.C
> @@ -0,0 +1,24 @@
> +// PR c++/61537
> +// { dg-do compile { target c++1y } }
I don't think this is a C++1y specific issue...
> +// { dg-options "" }
Also, likely minor detail, could you please explain why you need this?

Thanks for working on the bug!
Paolo.

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

* Re: [PATCH] Fix PR c++/61537
  2014-06-24 22:25 ` Paolo Carlini
@ 2014-06-24 23:05   ` Adam Butcher
  2014-06-25 12:46     ` Jason Merrill
  0 siblings, 1 reply; 8+ messages in thread
From: Adam Butcher @ 2014-06-24 23:05 UTC (permalink / raw)
  To: Paolo Carlini; +Cc: gcc-patches, Jason Merrill, Alexander Adam, Jonathan Wakely

On 2014-06-24 23:22, Paolo Carlini wrote:
> On 06/24/2014 01:40 AM, Adam Butcher wrote:
>> +// { dg-do compile { target c++1y } }
> I don't think this is a C++1y specific issue...

You're right.  I'm so used to creating pr testcases in that 
g++.dg/cpp1y dir, I automatically added the test there without engaging 
my brain!

>> +// { dg-options "" }
> Also, likely minor detail, could you please explain why you need 
> this?
>

Don't think I do; it was a copy from the most recent test in the cpp1y 
dir (another bad habit).  Same issue as before; need to engage brain. :)

I've fixed these issues up in my tree and moved the test to g++.dg.

Cheers,
Adam

diff --git a/gcc/testsuite/g++.dg/cpp1y/pr61537.C 
b/gcc/testsuite/g++.dg/pr61537.C
similarity index 79%
rename from gcc/testsuite/g++.dg/cpp1y/pr61537.C
rename to gcc/testsuite/g++.dg/pr61537.C
index 55761cd..12aaf58 100644
--- a/gcc/testsuite/g++.dg/cpp1y/pr61537.C
+++ b/gcc/testsuite/g++.dg/pr61537.C
@@ -1,6 +1,5 @@
  // PR c++/61537
-// { dg-do compile { target c++1y } }
-// { dg-options "" }
+// { dg-do compile }

  struct A {};


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

* Re: [PATCH] Fix PR c++/61537
  2014-06-24 23:05   ` Adam Butcher
@ 2014-06-25 12:46     ` Jason Merrill
  2014-06-25 20:05       ` Adam Butcher
  0 siblings, 1 reply; 8+ messages in thread
From: Jason Merrill @ 2014-06-25 12:46 UTC (permalink / raw)
  To: Adam Butcher, Paolo Carlini; +Cc: gcc-patches, Alexander Adam, Jonathan Wakely

On 06/24/2014 07:04 PM, Adam Butcher wrote:
> I've fixed these issues up in my tree and moved the test to g++.dg.

Please put it in g++.dg/template; I'd prefer not to clutter the top 
directory.

> +      bool template_parm_lists_apply
> +	  = parser->num_template_parameter_lists;
> +      for (cp_binding_level *s = current_binding_level; s; s = s->level_chain)
> +	if (s->kind == sk_function_parms)
> +	  template_parm_lists_apply = false;

Let's only start walking if there are template parameters, and stop 
walking when we reach them.

Jason

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

* Re: [PATCH] Fix PR c++/61537
  2014-06-25 12:46     ` Jason Merrill
@ 2014-06-25 20:05       ` Adam Butcher
  2014-06-25 20:57         ` Jason Merrill
  0 siblings, 1 reply; 8+ messages in thread
From: Adam Butcher @ 2014-06-25 20:05 UTC (permalink / raw)
  To: Jason Merrill, Paolo Carlini
  Cc: gcc-patches, Alexander Adam, Jonathan Wakely, Adam Butcher

	* 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

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

* Re: [PATCH] Fix PR c++/61537
  2014-06-25 20:05       ` Adam Butcher
@ 2014-06-25 20:57         ` Jason Merrill
  2014-06-26  5:08           ` Adam Butcher
  0 siblings, 1 reply; 8+ messages in thread
From: Jason Merrill @ 2014-06-25 20:57 UTC (permalink / raw)
  To: Adam Butcher, Paolo Carlini; +Cc: gcc-patches, Alexander Adam, Jonathan Wakely

OK, thanks.

Jason

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

* Re: [PATCH] Fix PR c++/61537
  2014-06-25 20:57         ` Jason Merrill
@ 2014-06-26  5:08           ` Adam Butcher
  2014-06-26 16:16             ` Jason Merrill
  0 siblings, 1 reply; 8+ messages in thread
From: Adam Butcher @ 2014-06-26  5:08 UTC (permalink / raw)
  To: Jason Merrill; +Cc: Paolo Carlini, gcc-patches, Alexander Adam, Jonathan Wakely

On 2014-06-25 21:57, Jason Merrill wrote:
> OK, thanks.
>

Do you want me to apply to 4.9 too?

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

* Re: [PATCH] Fix PR c++/61537
  2014-06-26  5:08           ` Adam Butcher
@ 2014-06-26 16:16             ` Jason Merrill
  0 siblings, 0 replies; 8+ messages in thread
From: Jason Merrill @ 2014-06-26 16:16 UTC (permalink / raw)
  To: Adam Butcher; +Cc: Paolo Carlini, gcc-patches, Alexander Adam, Jonathan Wakely

On 06/26/2014 01:08 AM, Adam Butcher wrote:
> Do you want me to apply to 4.9 too?

Please.

Jason

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

end of thread, other threads:[~2014-06-26 16:16 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-24 21:08 [PATCH] Fix PR c++/61537 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
2014-06-25 20:57         ` Jason Merrill
2014-06-26  5:08           ` Adam Butcher
2014-06-26 16:16             ` 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).