PR c++/89422 - ICE with -g and lambda in default arg in template.
authorJason Merrill <jason@redhat.com>
Thu, 21 Feb 2019 23:07:47 +0000 (18:07 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Thu, 21 Feb 2019 23:07:47 +0000 (18:07 -0500)
Here, we were trying to instantiate the default argument before setting
DECL_FRIEND_CONTEXT, so that the instantiated lambda ended up being treated
as part of the S template, which confused dwarf2out.

* pt.c (tsubst_function_decl): SET_DECL_FRIEND_CONTEXT sooner.

From-SVN: r269081

gcc/cp/ChangeLog
gcc/cp/pt.c
gcc/testsuite/g++.dg/cpp0x/lambda/lambda-defarg9.C [new file with mode: 0644]

index 228100ab21ff25c5fe40010a3ddd0fd694cbad81..2f99f2b95c8b53b69d631654dac1a1271eddf0ce 100644 (file)
@@ -1,3 +1,8 @@
+2019-02-21  Jason Merrill  <jason@redhat.com>
+
+       PR c++/89422 - ICE with -g and lambda in default arg in template.
+       * pt.c (tsubst_function_decl): SET_DECL_FRIEND_CONTEXT sooner.
+
 2019-02-21  Jason Merrill  <jason@redhat.com>
 
        PR c++/88419 - C++17 ICE with class template arg deduction.
index bd0a3d13bbe65fcdf118ddb5711da3b9ca6dcadf..76fb625a06847e5eee0ceeae69576d1f71f9f802 100644 (file)
@@ -13088,6 +13088,11 @@ tsubst_function_decl (tree t, tree args, tsubst_flags_t complain,
        set_constraints (r, ci);
       }
 
+  if (DECL_FRIEND_P (t) && DECL_FRIEND_CONTEXT (t))
+    SET_DECL_FRIEND_CONTEXT (r,
+                            tsubst (DECL_FRIEND_CONTEXT (t),
+                                    args, complain, in_decl));
+
   /* Set up the DECL_TEMPLATE_INFO for R.  There's no need to do
      this in the special friend case mentioned above where
      GEN_TMPL is NULL.  */
@@ -13149,11 +13154,6 @@ tsubst_function_decl (tree t, tree args, tsubst_flags_t complain,
           && !grok_op_properties (r, /*complain=*/true))
     return error_mark_node;
 
-  if (DECL_FRIEND_P (t) && DECL_FRIEND_CONTEXT (t))
-    SET_DECL_FRIEND_CONTEXT (r,
-                            tsubst (DECL_FRIEND_CONTEXT (t),
-                                    args, complain, in_decl));
-
   /* Possibly limit visibility based on template args.  */
   DECL_VISIBILITY (r) = VISIBILITY_DEFAULT;
   if (DECL_VISIBILITY_SPECIFIED (t))
diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-defarg9.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-defarg9.C
new file mode 100644 (file)
index 0000000..f0436ad
--- /dev/null
@@ -0,0 +1,10 @@
+// PR c++/89422
+// { dg-do compile { target c++11 } }
+// { dg-additional-options -g }
+
+template <int> struct S
+{
+  friend void foo (int a = []{ return 0; }()) {}
+  int b;
+};
+S<0> t;