semantics.c (lambda_expr_this_capture): In unevaluated context, just return the neare...
authorJason Merrill <jason@redhat.com>
Fri, 8 Mar 2013 16:04:02 +0000 (11:04 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Fri, 8 Mar 2013 16:04:02 +0000 (11:04 -0500)
* semantics.c (lambda_expr_this_capture): In unevaluated context,
just return the nearest 'this'.

From-SVN: r196550

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

index f9731a5..0aa5b4b 100644 (file)
@@ -1,5 +1,8 @@
 2013-03-08  Jason Merrill  <jason@redhat.com>
 
+       * semantics.c (lambda_expr_this_capture): In unevaluated context,
+       just return the nearest 'this'.
+
        PR c++/51494
        PR c++/51884
        PR c++/56222
index d11a4e4..233765a 100644 (file)
@@ -9513,6 +9513,11 @@ lambda_expr_this_capture (tree lambda)
 
   if (!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);
+
       error ("%<this%> was not captured for this lambda function");
       result = error_mark_node;
     }
diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-this12.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-this12.C
new file mode 100644 (file)
index 0000000..ef573b1
--- /dev/null
@@ -0,0 +1,13 @@
+// Uses of 'this' in unevaluated context are not odr-uses.
+// { dg-do compile { target c++11 } }
+
+struct A
+{
+  int f() {}
+  int i;
+
+  void foo()
+  {
+    [] () { sizeof(i); sizeof(f()); };
+  }
+};