Patchwork C++ PATCH for c++/54277 (wrong cv-quals in lambda)

login
register
mail settings
Submitter Jason Merrill
Date March 16, 2013, 7:28 p.m.
Message ID <5144C7DB.3090500@redhat.com>
Download mbox | patch
Permalink /patch/228243/
State New
Headers show

Comments

Jason Merrill - March 16, 2013, 7:28 p.m.
I have no idea why the existing code tried to deduce the desired quals 
from current_class_ref rather than just look at the object it has.  That 
gives the wrong answer if current_class_ref is for a lambda.

Tested x86_64-pc-linux-gnu, applying to trunk.

Patch

commit 6a9b91f58b18503ae7a4a55fe494c0336df10484
Author: Jason Merrill <jason@redhat.com>
Date:   Fri Feb 15 14:14:12 2013 -0500

    	PR c++/54277
    	* semantics.c (finish_non_static_data_member): Get the quals from
    	the object.

diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index efe09bb..d0cdf8b 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -1574,9 +1574,7 @@  finish_non_static_data_member (tree decl, tree object, tree qualifying_scope)
       else
 	{
 	  /* Set the cv qualifiers.  */
-	  int quals = (current_class_ref
-		       ? cp_type_quals (TREE_TYPE (current_class_ref))
-		       : TYPE_UNQUALIFIED);
+	  int quals = cp_type_quals (TREE_TYPE (object));
 
 	  if (DECL_MUTABLE_P (decl))
 	    quals &= ~TYPE_QUAL_CONST;
diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-this9.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-this9.C
new file mode 100644
index 0000000..07ddd08
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-this9.C
@@ -0,0 +1,19 @@ 
+// PR c++/54277
+// { dg-do compile { target c++11 } }
+
+struct Used
+{
+  void foo() { }
+};
+
+template <typename>
+struct S
+{
+  Used x;
+
+  void bar()
+  {
+    auto f = [this] { x.foo(); };
+    f();
+  }
+};