re PR c++/56699 (Failed for sizeof (non-static member) in lambda expression)
authorJason Merrill <jason@redhat.com>
Mon, 25 Mar 2013 22:06:36 +0000 (18:06 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Mon, 25 Mar 2013 22:06:36 +0000 (18:06 -0400)
PR c++/56699
* semantics.c (maybe_resolve_dummy): Make sure that the enclosing
class is derived from the type of the object.

From-SVN: r197069

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

index bac484498300ab3a99b36da7038ba9ce344e132c..6aaf1ddbebc5125f5973186b04dee4446a326573 100644 (file)
@@ -1,4 +1,8 @@
-2013-03-23  Jason Merrill  <jason@redhat.com>
+2013-03-25  Jason Merrill  <jason@redhat.com>
+
+       PR c++/56699
+       * semantics.c (maybe_resolve_dummy): Make sure that the enclosing
+       class is derived from the type of the object.
 
        PR c++/52014
        * semantics.c (lambda_expr_this_capture): Don't capture 'this' in
index fb38e8d70118110dd21db402212c61cf92915af6..127e2da016c00192a0fce6fe90093c780f6b4cd6 100644 (file)
@@ -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 (file)
index 0000000..736d5f5
--- /dev/null
@@ -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);};
+}