[PATCH] D151214: [clang][Sema] `-Wshadow` warns about shadowings by static local variables

2023-05-24 Thread Takuya Shimizu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG29dc47a9eeeb: [clang][Sema] `-Wshadow` warns about 
shadowings by static local variables (authored by hazohelet).

Changed prior to commit:
  https://reviews.llvm.org/D151214?vs=524709&id=525126#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151214/new/

https://reviews.llvm.org/D151214

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaDecl.cpp
  clang/test/Sema/warn-shadow.c
  clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
  clang/test/SemaCXX/warn-shadow.cpp

Index: clang/test/SemaCXX/warn-shadow.cpp
===
--- clang/test/SemaCXX/warn-shadow.cpp
+++ clang/test/SemaCXX/warn-shadow.cpp
@@ -2,6 +2,7 @@
 
 namespace {
   int i; // expected-note {{previous declaration is here}}
+  static int s; // expected-note {{previous declaration is here}}
 }
 
 namespace one {
@@ -31,6 +32,7 @@
 void foo() {
   int i; // expected-warning {{declaration shadows a variable in namespace '(anonymous)'}}
   int j; // expected-warning {{declaration shadows a variable in namespace 'one::two'}}
+  static int s; // expected-warning {{declaration shadows a variable in namespace '(anonymous)'}}
   int m;
   int mm;
   int mmm;
@@ -40,7 +42,7 @@
   static int data; // expected-note 1 {{previous declaration}}
   // expected-note@+1 1 {{previous declaration}}
   int field;
-  int f1, f2, f3, f4; // expected-note 8 {{previous declaration is here}}
+  int f1, f2, f3, f4; // expected-note 9 {{previous declaration is here}}
 
   typedef int a1; // expected-note 2 {{previous declaration}}
   using a2=int; // expected-note 2 {{previous declaration}}
@@ -66,6 +68,7 @@
 char *a2; // no warning
 char *jj; // no warning
 char *jjj; // no warning
+static char *f1; // expected-warning {{declaration shadows a field of 'A'}}
   }
 
   void test2() {
@@ -305,4 +308,4 @@
   }
 }
 
-}; // namespace structured_binding_tests
\ No newline at end of file
+}; // namespace structured_binding_tests
Index: clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
===
--- clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
+++ clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
@@ -14,11 +14,15 @@
 auto f2 = [&] { int var = 2; };  // no warning
 auto f3 = [=] (int param) { ; }; // no warning
 auto f4 = [&] (int param) { ; }; // no warning
+auto f5 = [=] { static int var = 1; };  // no warning
+auto f6 = [&] { static int var = 2; };  // no warning
 #else
 auto f1 = [=] { int var = 1; };  // expected-warning {{declaration shadows a local variable}}
 auto f2 = [&] { int var = 2; };  // expected-warning {{declaration shadows a local variable}}
 auto f3 = [=] (int param) { ; }; // expected-warning {{declaration shadows a local variable}}
 auto f4 = [&] (int param) { ; }; // expected-warning {{declaration shadows a local variable}}
+auto f5 = [=] { static int var = 1; };  // expected-warning {{declaration shadows a local variable}}
+auto f6 = [&] { static int var = 2; };  // expected-warning {{declaration shadows a local variable}}
 #endif
   }
 
@@ -67,11 +71,15 @@
 auto f2 = [] (int param) { ; }; // no warning
 auto f3 = [param] () { int var = 1; }; // no warning
 auto f4 = [var] (int param) { ; }; // no warning
+auto f5 = [param] () { static int var = 1; }; // no warning
+auto f6 = [] { static int var = 1; }; // no warning
 #else
 auto f1 = [] { int var = 1; }; // expected-warning {{declaration shadows a local variable}}
 auto f2 = [] (int param) { ; }; // expected-warning {{declaration shadows a local variable}}
 auto f3 = [param] () { int var = 1; }; // expected-warning {{declaration shadows a local variable}}
 auto f4 = [var] (int param) { ; }; // expected-warning {{declaration shadows a local variable}}
+auto f5 = [param] () { static int var = 1; }; // expected-warning {{declaration shadows a local variable}}
+auto f6 = [] { static int var = 1; }; // expected-warning {{declaration shadows a local variable}}
 #endif
   };
 
@@ -127,6 +135,11 @@
   int param = 0; // expected-warning {{declaration shadows a local variable}}
 };
   };
+  auto l7 = [&] {
+auto f1 = [param] { // expected-note {{variable 'param' is explicitly captured here}}
+  static int param = 0; // expected-warning {{declaration shadows a local variable}}
+};
+  };
 
   // Generic lambda arguments should work.
 #ifdef AVOID
Index: clang/test/Sema/warn-shadow.c
===
--- clang/test/Sema/warn-shadow.c
+++ clang/test/Sema/warn-shadow.c
@@ -1,18 +1,24 @@
 // RUN: %clang_cc1 -verify -fsyntax-only -fblocks -Wshadow %s
 
-int i;  // expected-note 3 {{previous declaration is here}}
+int i;  // expected-note 4 {{previous declaration is here}}
+static int s;  

[PATCH] D151214: [clang][Sema] `-Wshadow` warns about shadowings by static local variables

2023-05-23 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik accepted this revision.
shafik added a comment.
This revision is now accepted and ready to land.

LGTM




Comment at: clang/test/SemaCXX/warn-shadow.cpp:33
 void foo() {
   int i; // expected-warning {{declaration shadows a variable in namespace 
'(anonymous)'}}
   int j; // expected-warning {{declaration shadows a variable in namespace 
'one::two'}}

Note. it looks like gcc does not warn on shadowing for anonymous namespaces. I 
think it makes sense to warn in this case.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151214/new/

https://reviews.llvm.org/D151214

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D151214: [clang][Sema] `-Wshadow` warns about shadowings by static local variables

2023-05-23 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added inline comments.



Comment at: clang/docs/ReleaseNotes.rst:295
+- Clang's `-Wshadow` warning now warns about shadowings by static local 
variables
+  (`#62850: `_,
 




Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151214/new/

https://reviews.llvm.org/D151214

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D151214: [clang][Sema] `-Wshadow` warns about shadowings by static local variables

2023-05-23 Thread Takuya Shimizu via Phabricator via cfe-commits
hazohelet created this revision.
hazohelet added reviewers: aaron.ballman, tbaeder, shafik.
Herald added a project: All.
hazohelet requested review of this revision.
Herald added a project: clang.

This patch makes `-Wshadow` warn about the shadowings by static local variables.

Fixes https://github.com/llvm/llvm-project/issues/62850


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151214

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaDecl.cpp
  clang/test/Sema/warn-shadow.c
  clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
  clang/test/SemaCXX/warn-shadow.cpp

Index: clang/test/SemaCXX/warn-shadow.cpp
===
--- clang/test/SemaCXX/warn-shadow.cpp
+++ clang/test/SemaCXX/warn-shadow.cpp
@@ -2,6 +2,7 @@
 
 namespace {
   int i; // expected-note {{previous declaration is here}}
+  static int s; // expected-note {{previous declaration is here}}
 }
 
 namespace one {
@@ -31,6 +32,7 @@
 void foo() {
   int i; // expected-warning {{declaration shadows a variable in namespace '(anonymous)'}}
   int j; // expected-warning {{declaration shadows a variable in namespace 'one::two'}}
+  static int s; // expected-warning {{declaration shadows a variable in namespace '(anonymous)'}}
   int m;
   int mm;
   int mmm;
@@ -40,7 +42,7 @@
   static int data; // expected-note 1 {{previous declaration}}
   // expected-note@+1 1 {{previous declaration}}
   int field;
-  int f1, f2, f3, f4; // expected-note 8 {{previous declaration is here}}
+  int f1, f2, f3, f4; // expected-note 9 {{previous declaration is here}}
 
   typedef int a1; // expected-note 2 {{previous declaration}}
   using a2=int; // expected-note 2 {{previous declaration}}
@@ -66,6 +68,7 @@
 char *a2; // no warning
 char *jj; // no warning
 char *jjj; // no warning
+static char *f1; // expected-warning {{declaration shadows a field of 'A'}}
   }
 
   void test2() {
@@ -305,4 +308,4 @@
   }
 }
 
-}; // namespace structured_binding_tests
\ No newline at end of file
+}; // namespace structured_binding_tests
Index: clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
===
--- clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
+++ clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
@@ -14,11 +14,15 @@
 auto f2 = [&] { int var = 2; };  // no warning
 auto f3 = [=] (int param) { ; }; // no warning
 auto f4 = [&] (int param) { ; }; // no warning
+auto f5 = [=] { static int var = 1; };  // no warning
+auto f6 = [&] { static int var = 2; };  // no warning
 #else
 auto f1 = [=] { int var = 1; };  // expected-warning {{declaration shadows a local variable}}
 auto f2 = [&] { int var = 2; };  // expected-warning {{declaration shadows a local variable}}
 auto f3 = [=] (int param) { ; }; // expected-warning {{declaration shadows a local variable}}
 auto f4 = [&] (int param) { ; }; // expected-warning {{declaration shadows a local variable}}
+auto f5 = [=] { static int var = 1; };  // expected-warning {{declaration shadows a local variable}}
+auto f6 = [&] { static int var = 2; };  // expected-warning {{declaration shadows a local variable}}
 #endif
   }
 
@@ -67,11 +71,15 @@
 auto f2 = [] (int param) { ; }; // no warning
 auto f3 = [param] () { int var = 1; }; // no warning
 auto f4 = [var] (int param) { ; }; // no warning
+auto f5 = [param] () { static int var = 1; }; // no warning
+auto f6 = [] { static int var = 1; }; // no warning
 #else
 auto f1 = [] { int var = 1; }; // expected-warning {{declaration shadows a local variable}}
 auto f2 = [] (int param) { ; }; // expected-warning {{declaration shadows a local variable}}
 auto f3 = [param] () { int var = 1; }; // expected-warning {{declaration shadows a local variable}}
 auto f4 = [var] (int param) { ; }; // expected-warning {{declaration shadows a local variable}}
+auto f5 = [param] () { static int var = 1; }; // expected-warning {{declaration shadows a local variable}}
+auto f6 = [] { static int var = 1; }; // expected-warning {{declaration shadows a local variable}}
 #endif
   };
 
@@ -127,6 +135,11 @@
   int param = 0; // expected-warning {{declaration shadows a local variable}}
 };
   };
+  auto l7 = [&] {
+auto f1 = [param] { // expected-note {{variable 'param' is explicitly captured here}}
+  static int param = 0; // expected-warning {{declaration shadows a local variable}}
+};
+  };
 
   // Generic lambda arguments should work.
 #ifdef AVOID
Index: clang/test/Sema/warn-shadow.c
===
--- clang/test/Sema/warn-shadow.c
+++ clang/test/Sema/warn-shadow.c
@@ -1,18 +1,24 @@
 // RUN: %clang_cc1 -verify -fsyntax-only -fblocks -Wshadow %s
 
-int i;  // expected-note 3 {{previous declaration is here}}
+int i;  // expected-note 4 {{previous declaration is here}}
+static int s;   // expected-note 2 {{