Patchwork C++ PATCH for c++/56699 (ICE with sizeof member of unrelated class in lambda)

login
register
mail settings
Submitter Jason Merrill
Date March 25, 2013, 10:04 p.m.
Message ID <5150C9FF.4050404@redhat.com>
Download mbox | patch
Permalink /patch/230995/
State New
Headers show

Comments

Jason Merrill - March 25, 2013, 10:04 p.m.
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.

Patch

commit 5ac81af97e551d65ad46443973d337d388f35297
Author: Jason Merrill <jason@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);};
+}