[C++ Patch/RFC] PR 62219

Paolo Carlini paolo.carlini@oracle.com
Fri Sep 19 15:40:00 GMT 2014


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.

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

-------------- next part --------------
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 )
+  {
+    [](){};
+  }
+};


More information about the Gcc-patches mailing list