diff mbox

[C++1y] [Implicit Fix instantiation of implicit function template forward declarations.

Message ID aab3c5f0904dd90157f3f33892a74bfe@imap.force9.net
State New
Headers show

Commit Message

Adam Butcher Sept. 23, 2013, 6:53 a.m. UTC
Hi Jason,

I noticed that, although implicit function template declarations were 
accepted.  They weren't setup correctly and didn't instantiate properly.

The following patch fixes this by moving finish_fully_implicit_template 
to the end of cp_parser_init_declarator.  OK to go with the others?

Cheers,
Adam


     Fix instantiation of implicit function template forward 
declarations.

     	* parser.c (cp_parser_init_declarator): Defer calling
     	finish_fully_implicit_template for forward declarations until 
after
     	other decl processing is complete.  Cleanup for clarity: Extract 
'else'
     	case after 'if' containing unconditional return.

Comments

Jason Merrill Sept. 23, 2013, 6:03 p.m. UTC | #1
On 09/23/2013 01:53 AM, Adam Butcher wrote:
> +      if (member_p)
> +    decl = finish_fully_implicit_template (parser, decl);
> +      else
> +    finish_fully_implicit_template (parser, /*member_decl_opt=*/0);

Why don't we want to return the template for the non-member case?

Jason
Adam Butcher Sept. 23, 2013, 6:50 p.m. UTC | #2
On 23.09.2013 19:03, Jason Merrill wrote:
> On 09/23/2013 01:53 AM, Adam Butcher wrote:
>> +  if (member_p)
>> +    decl = finish_fully_implicit_template (parser, decl);
>> +  else
>> +    finish_fully_implicit_template (parser, /*member_decl_opt=*/0);
>
> Why don't we want to return the template for the non-member case?
>
If the decl is passed to finish_fully_implicit_template it is 
considered to be a member and the finished member returned.  In the 
non-member case, nullptr is returned.
diff mbox

Patch

diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 82abf7c..f3133f3 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -16318,8 +16318,7 @@  cp_parser_init_declarator (cp_parser* parser,
  			       "a function-definition is not allowed here");
  	      return error_mark_node;
  	    }
-	  else
-	    {
+
  	  location_t func_brace_location
  	    = cp_lexer_peek_token (parser->lexer)->location;

@@ -16357,9 +16356,6 @@  cp_parser_init_declarator (cp_parser* parser,
  	  return decl;
  	}
      }
-      else if (parser->fully_implicit_function_template_p)
-	decl = finish_fully_implicit_template (parser, decl);
-    }

    /* [dcl.dcl]

@@ -16581,6 +16577,15 @@  cp_parser_init_declarator (cp_parser* parser,
    if (!friend_p && pushed_scope)
      pop_scope (pushed_scope);

+  if (function_declarator_p (declarator)
+      && parser->fully_implicit_function_template_p)
+    {
+      if (member_p)
+	decl = finish_fully_implicit_template (parser, decl);
+      else
+	finish_fully_implicit_template (parser, /*member_decl_opt=*/0);
+    }
+
    return decl;
  }