This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

C++ PATCH for c++/61566 (ICE with lambda in template default arg)


decl_mangling_context was failing to recognize a lambda in template context as a lambda.

Tested x86_64-pc-linux-gnu, applying to 4.9 and trunk.
commit 1ba7cf95c0b024c7a3372e0734d7bf620f31dd14
Author: Jason Merrill <jason@redhat.com>
Date:   Mon Jun 30 12:08:09 2014 -0400

    	PR c++/61566
    	* mangle.c (decl_mangling_context): Look through a TEMPLATE_DECL.

diff --git a/gcc/cp/mangle.c b/gcc/cp/mangle.c
index ac1c1da..02c05d4 100644
--- a/gcc/cp/mangle.c
+++ b/gcc/cp/mangle.c
@@ -742,6 +742,10 @@ decl_mangling_context (tree decl)
   if (tcontext != NULL_TREE)
     return tcontext;
 
+  if (TREE_CODE (decl) == TEMPLATE_DECL
+      && DECL_TEMPLATE_RESULT (decl))
+    decl = DECL_TEMPLATE_RESULT (decl);
+
   if (TREE_CODE (decl) == TYPE_DECL
       && LAMBDA_TYPE_P (TREE_TYPE (decl)))
     {
diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-template13.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-template13.C
new file mode 100644
index 0000000..adbb4db
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-template13.C
@@ -0,0 +1,20 @@
+// PR c++/61566
+// { dg-do compile { target c++11 } }
+
+struct function
+{
+  template < typename _Functor>
+  function (_Functor);
+};
+
+struct C
+{
+  template <typename T>
+  void foo (T, function = [] {});
+};
+
+void bar ()
+{
+  C c;
+  c.foo (1);
+}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]