diff mbox

[C++,Patch/RFC] PR 62219

Message ID 541C4E70.3000803@oracle.com
State New
Headers show

Commit Message

Paolo Carlini Sept. 19, 2014, 3:40 p.m. UTC
Hi,

I had a quick look at this issue and it immediately reminded me 
c++/60605, which Jason fixed by handling local functions at the 
beginning of check_default_tmpl_args. In the present case of:

template< class = void >
struct S
{
   friend void foo( S )
   {
     [](){};
   }
};

it occurs to me that we may want to simply handle the operator() of the 
lambda in the same way?!? Anyway, the below passes testing...

Thanks!
Paolo.

/////////////////////

Comments

Jason Merrill Sept. 19, 2014, 5:32 p.m. UTC | #1
On 09/19/2014 11:40 AM, Paolo Carlini wrote:
>    if (TREE_CODE (CP_DECL_CONTEXT (decl)) == FUNCTION_DECL
> -      || (TREE_CODE (decl) == FUNCTION_DECL && DECL_LOCAL_FUNCTION_P (decl)))
> +      || (TREE_CODE (decl) == FUNCTION_DECL
> +	  && (DECL_LOCAL_FUNCTION_P (decl) || LAMBDA_FUNCTION_P (decl))))
>      /* You can't have a function template declaration in a local
>         scope, nor you can you define a member of a class template in a
>         local scope.  */

Rather than adding it to this condition, let's group the new test with 
the other lambda test, immediately below.

Jason
diff mbox

Patch

Index: cp/pt.c
===================================================================
--- cp/pt.c	(revision 215393)
+++ cp/pt.c	(working copy)
@@ -4450,7 +4450,8 @@  check_default_tmpl_args (tree decl, tree parms, bo
      class template.  */
 
   if (TREE_CODE (CP_DECL_CONTEXT (decl)) == FUNCTION_DECL
-      || (TREE_CODE (decl) == FUNCTION_DECL && DECL_LOCAL_FUNCTION_P (decl)))
+      || (TREE_CODE (decl) == FUNCTION_DECL
+	  && (DECL_LOCAL_FUNCTION_P (decl) || LAMBDA_FUNCTION_P (decl))))
     /* You can't have a function template declaration in a local
        scope, nor you can you define a member of a class template in a
        local scope.  */
Index: testsuite/g++.dg/cpp0x/lambda/lambda-template14.C
===================================================================
--- testsuite/g++.dg/cpp0x/lambda/lambda-template14.C	(revision 0)
+++ testsuite/g++.dg/cpp0x/lambda/lambda-template14.C	(working copy)
@@ -0,0 +1,11 @@ 
+// PR c++/62219
+// { dg-do compile { target c++11 } }
+
+template< class = void >
+struct S
+{
+  friend void foo( S )
+  {
+    [](){};
+  }
+};