John McCall | 9a8cb8d | 2010-03-16 21:50:59 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -verify -fsyntax-only -Wshadow %s |
| 2 | |
| 3 | namespace { |
| 4 | int i; // expected-note {{previous declaration is here}} |
| 5 | } |
| 6 | |
| 7 | namespace one { |
| 8 | namespace two { |
| 9 | int j; // expected-note {{previous declaration is here}} |
| 10 | } |
| 11 | } |
| 12 | |
| 13 | namespace xx { |
| 14 | int m; |
| 15 | } |
| 16 | namespace yy { |
| 17 | int m; |
| 18 | } |
| 19 | |
| 20 | using namespace one::two; |
| 21 | using namespace xx; |
| 22 | using namespace yy; |
| 23 | |
| 24 | void foo() { |
| 25 | int i; // expected-warning {{declaration shadows a variable in namespace '<anonymous>'}} |
| 26 | int j; // expected-warning {{declaration shadows a variable in namespace 'one::two'}} |
| 27 | int m; |
| 28 | } |
| 29 | |
| 30 | class A { |
| 31 | static int data; // expected-note {{previous declaration}} |
| 32 | int field; // expected-note {{previous declaration}} |
| 33 | |
| 34 | void test() { |
| 35 | char *field; // expected-warning {{declaration shadows a field of 'A'}} |
| 36 | char *data; // expected-warning {{declaration shadows a static data member of 'A'}} |
| 37 | } |
| 38 | }; |
John McCall | a369a95 | 2010-03-20 04:12:52 +0000 | [diff] [blame] | 39 | |
| 40 | // TODO: this should warn, <rdar://problem/5018057> |
| 41 | class B : A { |
| 42 | int data; |
| 43 | static int field; |
| 44 | }; |
Argyrios Kyrtzidis | 36eb5e4 | 2011-01-31 07:04:54 +0000 | [diff] [blame] | 45 | |
| 46 | // rdar://8900456 |
| 47 | namespace rdar8900456 { |
| 48 | struct Foo { |
| 49 | static void Baz(); |
| 50 | private: |
| 51 | int Bar; |
| 52 | }; |
| 53 | |
| 54 | void Foo::Baz() { |
| 55 | double Bar = 12; // Don't warn. |
| 56 | } |
| 57 | } |
Argyrios Kyrtzidis | 651f86f | 2011-02-08 18:21:25 +0000 | [diff] [blame] | 58 | |
| 59 | // http://llvm.org/PR9160 |
| 60 | namespace PR9160 { |
| 61 | struct V { |
| 62 | V(int); |
| 63 | }; |
| 64 | struct S { |
| 65 | V v; |
| 66 | static void m() { |
| 67 | if (1) { |
| 68 | V v(0); |
| 69 | } |
| 70 | } |
| 71 | }; |
| 72 | } |
Argyrios Kyrtzidis | 865dd8c | 2011-04-25 21:39:50 +0000 | [diff] [blame] | 73 | |
| 74 | extern int bob; // expected-note {{previous declaration is here}} |
| 75 | |
| 76 | // rdar://8883302 |
| 77 | void rdar8883302() { |
| 78 | extern int bob; // don't warn for shadowing. |
| 79 | } |
| 80 | |
| 81 | void test8() { |
| 82 | int bob; // expected-warning {{declaration shadows a variable in the global namespace}} |
| 83 | } |