]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
PR c++/84520 - ICE with generic lambda in NSDMI.
authorJason Merrill <jason@redhat.com>
Tue, 27 Feb 2018 04:22:24 +0000 (23:22 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Tue, 27 Feb 2018 04:22:24 +0000 (23:22 -0500)
* lambda.c (lambda_expr_this_capture): Don't look for fake NSDMI
'this' in a generic lambda instantiation.

From-SVN: r258027

gcc/cp/ChangeLog
gcc/cp/lambda.c
gcc/testsuite/g++.dg/cpp1y/lambda-generic-nsdmi1.C [new file with mode: 0644]

index 9f396c338aef708b4e4136c671ab09f86581b41b..89dcffcba2e5e65fedf3348bef733700c3d80b95 100644 (file)
@@ -1,3 +1,9 @@
+2018-02-26  Jason Merrill  <jason@redhat.com>
+
+       PR c++/84520 - ICE with generic lambda in NSDMI.
+       * lambda.c (lambda_expr_this_capture): Don't look for fake NSDMI
+       'this' in a generic lambda instantiation.
+
 2018-02-16  Jason Merrill  <jason@redhat.com>
 
        PR c++/84151 - unnecessary volatile load with static member.
index 91a5c1a0b0877369d3d479f67eab975c9977f1c3..ea15c26ae3ee147c4da1f261ef84b88efd6ca259 100644 (file)
@@ -665,11 +665,14 @@ lambda_expr_this_capture (tree lambda, bool add_capture_p)
                                     lambda_stack);
 
          if (LAMBDA_EXPR_EXTRA_SCOPE (tlambda)
+             && !COMPLETE_TYPE_P (LAMBDA_EXPR_CLOSURE (tlambda))
              && TREE_CODE (LAMBDA_EXPR_EXTRA_SCOPE (tlambda)) == FIELD_DECL)
            {
              /* In an NSDMI, we don't have a function to look up the decl in,
                 but the fake 'this' pointer that we're using for parsing is
-                in scope_chain.  */
+                in scope_chain.  But if the closure is already complete, we're
+                in an instantiation of a generic lambda, and the fake 'this'
+                is gone.  */
              init = scope_chain->x_current_class_ptr;
              gcc_checking_assert
                (init && (TREE_TYPE (TREE_TYPE (init))
diff --git a/gcc/testsuite/g++.dg/cpp1y/lambda-generic-nsdmi1.C b/gcc/testsuite/g++.dg/cpp1y/lambda-generic-nsdmi1.C
new file mode 100644 (file)
index 0000000..89ce519
--- /dev/null
@@ -0,0 +1,8 @@
+// PR c++/84520
+// { dg-do compile { target c++14 } }
+
+struct A
+{
+  static void foo(int);
+  void (*f)(int) = [](auto i) { foo(i); };
+};