This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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.
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();
+  }
+};

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]