Eli Friedman | e4851f2 | 2012-10-23 20:19:32 +0000 | [diff] [blame] | 1 | // RUN: %clang -Wmissing-variable-declarations -fsyntax-only -Xclang -verify %s |
| 2 | |
| 3 | // Variable declarations that should trigger a warning. |
| 4 | int vbad1; // expected-warning{{no previous extern declaration for non-static variable 'vbad1'}} |
| 5 | int vbad2 = 10; // expected-warning{{no previous extern declaration for non-static variable 'vbad2'}} |
| 6 | |
Eli Friedman | 6c8b649 | 2012-10-24 20:14:09 +0000 | [diff] [blame] | 7 | namespace x { |
| 8 | int vbad3; // expected-warning{{no previous extern declaration for non-static variable 'vbad3'}} |
| 9 | } |
| 10 | |
Eli Friedman | e4851f2 | 2012-10-23 20:19:32 +0000 | [diff] [blame] | 11 | // Variable declarations that should not trigger a warning. |
| 12 | static int vgood1; |
| 13 | extern int vgood2; |
| 14 | int vgood2; |
| 15 | static struct { |
| 16 | int mgood1; |
| 17 | } vgood3; |
| 18 | |
| 19 | // Functions should never trigger a warning. |
| 20 | void fgood1(void); |
| 21 | void fgood2(void) { |
| 22 | int lgood1; |
| 23 | static int lgood2; |
| 24 | } |
| 25 | static void fgood3(void) { |
| 26 | int lgood3; |
| 27 | static int lgood4; |
| 28 | } |
| 29 | |
| 30 | // Structures, namespaces and classes should be unaffected. |
| 31 | struct sgood1 { |
| 32 | int mgood2; |
| 33 | }; |
| 34 | struct { |
| 35 | int mgood3; |
| 36 | } sgood2; |
| 37 | class CGood1 { |
| 38 | static int MGood1; |
| 39 | }; |
| 40 | int CGood1::MGood1; |
| 41 | namespace { |
| 42 | int mgood4; |
| 43 | } |