re PR c++/56710 (Using reserved double underscore variable name in a lambda causes...
authorJason Merrill <jason@redhat.com>
Thu, 28 Mar 2013 18:20:45 +0000 (14:20 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Thu, 28 Mar 2013 18:20:45 +0000 (14:20 -0400)
PR c++/56710
* semantics.c (finish_member_declaration): Don't push closure
members.

From-SVN: r197211

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

index b20415391f7205df7ab45f356897ddab7e6dea67..2b02880c63f02d2575a897df3e34e69fcd3159ff 100644 (file)
@@ -1,5 +1,9 @@
 2013-03-28  Jason Merrill  <jason@redhat.com>
 
+       PR c++/56710
+       * semantics.c (finish_member_declaration): Don't push closure
+       members.
+
        * name-lookup.c (pushdecl_maybe_friend_1): Use
        nonlambda_method_basetype and current_nonlambda_class_type.
 
index 0b8e2f7488810f79e58ad2fd8bb24731d31389ce..ad1c209b2362016619d6f8a778329e2a83e2c5f4 100644 (file)
@@ -2719,8 +2719,10 @@ finish_member_declaration (tree decl)
                                              /*friend_p=*/0);
        }
     }
-  /* Enter the DECL into the scope of the class.  */
-  else if (pushdecl_class_level (decl))
+  /* Enter the DECL into the scope of the class, if the class
+     isn't a closure (whose fields are supposed to be unnamed).  */
+  else if (CLASSTYPE_LAMBDA_EXPR (current_class_type)
+          || pushdecl_class_level (decl))
     {
       if (TREE_CODE (decl) == USING_DECL)
        {
diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-names1.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-names1.C
new file mode 100644 (file)
index 0000000..df2b037
--- /dev/null
@@ -0,0 +1,9 @@
+// PR c++/56710
+// { dg-options "-std=c++11 -Wall" }
+
+int main()
+{
+    int t = 0;
+    return [&]() -> int {int __t; __t = t; return __t; }();
+    return [&t]() -> int {int __t; __t = t; return __t; }();
+}