Hi,

in this ICE on valid, 4.8/4.9 Regression, the problem is that, for a lambda in an NSDMI context, the early return of lambda_expr_this_capture:

   /* In unevaluated context this isn't an odr-use, so just return the
      nearest 'this'.  */
   if (cp_unevaluated_operand)
     return lookup_name (this_identifier);

fails to find a this_identifier. This is expected, in a NSDMI context, as also clarified from the comment a few lines below. Thus I'm handling the issue the same way, that is by way of scope_chain->x_current_class_ptr.

Tested x86_64-linux.

Thanks!
Paolo.

////////////////////////////
/cp
2013-10-17  Paolo Carlini  <paolo.carl...@oracle.com>

        PR c++/58596
        * lambda.c (lambda_expr_this_capture): Handle NSDMIs in the
        cp_unevaluated_operand case.

/testsuite
2013-10-17  Paolo Carlini  <paolo.carl...@oracle.com>

        PR c++/58596
        * g++.dg/cpp0x/lambda/lambda-nsdmi5.C: New
Index: cp/lambda.c
===================================================================
--- cp/lambda.c (revision 203744)
+++ cp/lambda.c (working copy)
@@ -628,7 +628,14 @@ lambda_expr_this_capture (tree lambda)
   /* In unevaluated context this isn't an odr-use, so just return the
      nearest 'this'.  */
   if (cp_unevaluated_operand)
-    return lookup_name (this_identifier);
+    {
+      /* In an NSDMI the fake 'this' pointer that we're using for
+        parsing is in scope_chain.  */
+      if (LAMBDA_EXPR_EXTRA_SCOPE (lambda)
+         && TREE_CODE (LAMBDA_EXPR_EXTRA_SCOPE (lambda)) == FIELD_DECL)
+       return scope_chain->x_current_class_ptr;
+      return lookup_name (this_identifier);
+    }
 
   /* Try to default capture 'this' if we can.  */
   if (!this_capture
Index: testsuite/g++.dg/cpp0x/lambda/lambda-nsdmi5.C
===================================================================
--- testsuite/g++.dg/cpp0x/lambda/lambda-nsdmi5.C       (revision 0)
+++ testsuite/g++.dg/cpp0x/lambda/lambda-nsdmi5.C       (working copy)
@@ -0,0 +1,7 @@
+// PR c++/58596
+// { dg-do compile { target c++11 } }
+
+struct A
+{
+  int i = [] { return decltype(i)(); }();
+};

Reply via email to