re PR c++/55357 (-Wshadow warns about lambda function parameters matching variables...
authorJason Merrill <jason@redhat.com>
Sun, 17 Mar 2013 02:38:01 +0000 (22:38 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Sun, 17 Mar 2013 02:38:01 +0000 (22:38 -0400)
PR c++/55357
* semantics.c (maybe_add_lambda_conv_op): Clear DECL_NAME of copied
parms to avoid duplicate -Wshadow warnings.

From-SVN: r196739

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

index c0e15426719fed322ff7a2bb9188bef880bd5ffd..22d408b2d2f89595efa28bb9b7f5dddf5558d6ba 100644 (file)
@@ -1,5 +1,9 @@
 2013-03-16  Jason Merrill  <jason@redhat.com>
 
+       PR c++/55357
+       * semantics.c (maybe_add_lambda_conv_op): Clear DECL_NAME of copied
+       parms to avoid duplicate -Wshadow warnings.
+
        * search.c (lookup_base): Handle NULL_TREE.
 
        PR c++/56481
index 20fe2433777ce8de3ce95eb02bedf74cad9148b8..e46b4bfae9ce50cd2e065133bdcafcee801c061d 100644 (file)
@@ -9678,7 +9678,11 @@ maybe_add_lambda_conv_op (tree type)
   DECL_STATIC_FUNCTION_P (fn) = 1;
   DECL_ARGUMENTS (fn) = copy_list (DECL_CHAIN (DECL_ARGUMENTS (callop)));
   for (arg = DECL_ARGUMENTS (fn); arg; arg = DECL_CHAIN (arg))
-    DECL_CONTEXT (arg) = fn;
+    {
+      /* Avoid duplicate -Wshadow warnings.  */
+      DECL_NAME (arg) = NULL_TREE;
+      DECL_CONTEXT (arg) = fn;
+    }
   if (nested)
     DECL_INTERFACE_KNOWN (fn) = 1;
 
diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-shadow1.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-shadow1.C
new file mode 100644 (file)
index 0000000..bb06bfe
--- /dev/null
@@ -0,0 +1,9 @@
+// PR c++/55357
+// { dg-options "-std=c++11 -Wshadow" }
+
+int main() {
+  int x = 1;                     // { dg-warning "shadowed" }
+  auto const lambda = [](int x) { // { dg-warning "shadows" }
+    return x;
+  };
+}