My maybe_resolve_dummy patch failed to consider that 'this' might not be
relevant to the type of the dummy object.
Tested x86_64-pc-linux-gnu, applying to trunk and 4.8.
commit 5ac81af97e551d65ad46443973d337d388f35297
Author: Jason Merrill <ja...@redhat.com>
Date: Mon Mar 25 17:14:04 2013 -0400
PR c++/56699
* semantics.c (maybe_resolve_dummy): Make sure that the enclosing
class is derived from the type of the object.
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index fb38e8d..127e2da 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -9565,7 +9565,8 @@ maybe_resolve_dummy (tree object)
if (type != current_class_type
&& current_class_type
- && LAMBDA_TYPE_P (current_class_type))
+ && LAMBDA_TYPE_P (current_class_type)
+ && DERIVED_FROM_P (type, current_nonlambda_class_type ()))
{
/* In a lambda, need to go through 'this' capture. */
tree lam = CLASSTYPE_LAMBDA_EXPR (current_class_type);
diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-this16.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-this16.C
new file mode 100644
index 0000000..736d5f5
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-this16.C
@@ -0,0 +1,28 @@
+// PR c++/56699
+// { dg-require-effective-target c++11 }
+
+struct A
+{
+ int a;
+};
+
+struct T
+{
+ int x;
+
+ T() : x([]{
+ sizeof(::A::a);
+ return 0;
+ }())
+ {}
+};
+
+struct B
+{
+ int a;
+};
+
+void f()
+{
+ []{sizeof(B::a);};
+}