[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / Sema / warn-shadow.c
blob5cc27560496dfe89ddf127adfb9af51e564c1f41
1 // RUN: %clang_cc1 -verify -fsyntax-only -fblocks -Wshadow %s
3 int i; // expected-note 4 {{previous declaration is here}}
4 static int s; // expected-note 2 {{previous declaration is here}}
6 void foo(void) {
7 int pass1;
8 int i; // expected-warning {{declaration shadows a variable in the global scope}} \
9 // expected-note {{previous declaration is here}}
10 int s; // expected-warning {{declaration shadows a variable in the global scope}} \
11 // expected-note {{previous declaration is here}}
13 int pass2;
14 int i; // expected-warning {{declaration shadows a local variable}} \
15 // expected-note {{previous declaration is here}}
16 int s; // expected-warning {{declaration shadows a local variable}} \
17 // expected-note {{previous declaration is here}}
19 int pass3;
20 int i; // expected-warning {{declaration shadows a local variable}}
21 int s; // expected-warning {{declaration shadows a local variable}}
25 int sin; // okay; 'sin' has not been declared, even though it's a builtin.
28 void (^test1)(int) = ^(int i) { // expected-warning {{declaration shadows a variable in the global scope}} \
29 // expected-note{{previous declaration is here}}
31 int i; // expected-warning {{declaration shadows a local variable}} \
32 // expected-note{{previous declaration is here}}
34 (^(int i) { return i; })(i); //expected-warning {{declaration shadows a local variable}}
39 struct test2 {
40 int i;
43 void test3(void) {
44 struct test4 {
45 int i;
49 void test4(int i) { // expected-warning {{declaration shadows a variable in the global scope}}
52 // Don't warn about shadowing for function declarations.
53 void test5(int i);
54 void test6(void (*f)(int i)) {}
55 void test7(void *context, void (*callback)(void *context)) {}
57 extern int bob; // expected-note {{previous declaration is here}}
59 void rdar8883302(void) {
60 extern int bob; // don't warn for shadowing.
63 void test8(void) {
64 int bob; // expected-warning {{declaration shadows a variable in the global scope}}
67 enum PR24718_1{pr24718}; // expected-note {{previous declaration is here}}
68 void PR24718(void) {
69 enum PR24718_2{pr24718}; // expected-warning {{declaration shadows a variable in the global scope}}
72 struct PR24718_3;
73 struct PR24718_4 {
74 enum {
75 PR24718_3 // Does not shadow a type.
79 void static_locals() {
80 static int i; // expected-warning {{declaration shadows a variable in the global scope}}
81 // expected-note@-1 {{previous definition is here}}
82 // expected-note@-2 {{previous declaration is here}}
83 int i; // expected-error {{non-static declaration of 'i' follows static declaration}}
84 static int foo; // expected-note {{previous declaration is here}}
85 static int hoge; // expected-note {{previous declaration is here}}
86 int s; // expected-warning {{declaration shadows a variable in the global scope}}
88 static int foo; // expected-warning {{declaration shadows a local variable}}
89 // expected-note@-1 {{previous declaration is here}}
90 static int i; // expected-warning {{declaration shadows a local variable}}
91 // expected-note@-1 {{previous declaration is here}}
92 int hoge; // expected-warning {{declaration shadows a local variable}}
94 static int foo; // expected-warning {{declaration shadows a local variable}}
95 int i; // expected-warning {{declaration shadows a local variable}}
96 extern int hoge;