public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* C++ PATCH for c++/55357 (-Wshadow and lambdas)
@ 2013-03-17  1:38 Jason Merrill
  0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2013-03-17  1:38 UTC (permalink / raw)
  To: gcc-patches List

[-- Attachment #1: Type: text/plain, Size: 325 bytes --]

The submitter of this PR suggested that we don't want to warn about 
shadowing of a local variable by a lambda parameter; I think we do, 
since local variables can be used in lambdas, but we don't want a 
duplicate warning when we copy the parameter into the conversion thunk.

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

[-- Attachment #2: 55357.patch --]
[-- Type: text/x-patch, Size: 1307 bytes --]

commit cd911b455722c1b88d21ac7dcb192aae53ef7f16
Author: Jason Merrill <jason@redhat.com>
Date:   Tue Mar 5 14:25:04 2013 -0500

    	PR c++/55357
    	* semantics.c (maybe_add_lambda_conv_op): Clear DECL_NAME of copied
    	parms to avoid duplicate -Wshadow warnings.

diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 9d2f3f4..d39469d 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -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
index 0000000..bb06bfe
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-shadow1.C
@@ -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;
+  };
+}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2013-03-17  1:38 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-17  1:38 C++ PATCH for c++/55357 (-Wshadow and lambdas) Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).