Richard Smith | 85b29a4 | 2012-02-17 01:35:32 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -pedantic -Wunused-label -verify -x c %s |
Nick Lewycky | ba5f6ec | 2010-04-24 01:30:46 +0000 | [diff] [blame] | 2 | // RUN: cp %s %t |
Richard Smith | 2315318 | 2011-09-06 03:01:15 +0000 | [diff] [blame] | 3 | // RUN: not %clang_cc1 -pedantic -Wunused-label -fixit -x c %t |
Nick Lewycky | ba5f6ec | 2010-04-24 01:30:46 +0000 | [diff] [blame] | 4 | // RUN: grep -v CHECK %t > %t2 |
Anna Zaks | d5612a2 | 2011-07-28 20:52:06 +0000 | [diff] [blame] | 5 | // RUN: %clang_cc1 -pedantic -Wunused-label -Werror -x c %t |
Nick Lewycky | ba5f6ec | 2010-04-24 01:30:46 +0000 | [diff] [blame] | 6 | // RUN: FileCheck -input-file=%t2 %t |
Douglas Gregor | 9b3064b | 2009-04-01 22:41:11 +0000 | [diff] [blame] | 7 | |
| 8 | /* This is a test of the various code modification hints that are |
Douglas Gregor | fe057ac | 2009-04-02 03:20:30 +0000 | [diff] [blame] | 9 | provided as part of warning or extension diagnostics. All of the |
| 10 | warnings will be fixed by -fixit, and the resulting file should |
| 11 | compile cleanly with -Werror -pedantic. */ |
Daniel Dunbar | d8aefab | 2009-11-17 22:25:16 +0000 | [diff] [blame] | 12 | |
| 13 | // FIXME: FIX-IT should add #include <string.h>? |
| 14 | int strcmp(const char *s1, const char *s2); |
Douglas Gregor | 9b3064b | 2009-04-01 22:41:11 +0000 | [diff] [blame] | 15 | |
Richard Smith | 85b29a4 | 2012-02-17 01:35:32 +0000 | [diff] [blame] | 16 | void f0(void) { }; // expected-warning {{';'}} |
Douglas Gregor | 9b3064b | 2009-04-01 22:41:11 +0000 | [diff] [blame] | 17 | |
| 18 | struct s { |
Richard Smith | 85b29a4 | 2012-02-17 01:35:32 +0000 | [diff] [blame] | 19 | int x, y;; // expected-warning {{extra ';'}} |
Douglas Gregor | 9b3064b | 2009-04-01 22:41:11 +0000 | [diff] [blame] | 20 | }; |
| 21 | |
Daniel Dunbar | 266cc53 | 2009-11-14 19:25:21 +0000 | [diff] [blame] | 22 | // CHECK: _Complex double cd; |
Richard Smith | 85b29a4 | 2012-02-17 01:35:32 +0000 | [diff] [blame] | 23 | _Complex cd; // expected-warning {{assuming '_Complex double'}} |
Douglas Gregor | 9b3064b | 2009-04-01 22:41:11 +0000 | [diff] [blame] | 24 | |
Daniel Dunbar | 266cc53 | 2009-11-14 19:25:21 +0000 | [diff] [blame] | 25 | // CHECK: struct s s0 = { .y = 5 }; |
Richard Smith | 85b29a4 | 2012-02-17 01:35:32 +0000 | [diff] [blame] | 26 | struct s s0 = { y: 5 }; // expected-warning {{GNU old-style}} |
Daniel Dunbar | 266cc53 | 2009-11-14 19:25:21 +0000 | [diff] [blame] | 27 | |
| 28 | // CHECK: int array0[5] = { [3] = 3 }; |
Richard Smith | 85b29a4 | 2012-02-17 01:35:32 +0000 | [diff] [blame] | 29 | int array0[5] = { [3] 3 }; // expected-warning {{GNU 'missing ='}} |
Douglas Gregor | a3a8351 | 2009-04-01 23:51:29 +0000 | [diff] [blame] | 30 | |
Richard Smith | 85b29a4 | 2012-02-17 01:35:32 +0000 | [diff] [blame] | 31 | // CHECK: int x |
| 32 | // CHECK: int y |
| 33 | void f1(x, y) // expected-warning 2{{defaulting to type 'int'}} |
Douglas Gregor | a3a8351 | 2009-04-01 23:51:29 +0000 | [diff] [blame] | 34 | { |
| 35 | } |
| 36 | |
| 37 | int i0 = { 17 }; |
| 38 | |
Argyrios Kyrtzidis | b5303aa | 2011-06-24 17:28:29 +0000 | [diff] [blame] | 39 | #define ONE 1 |
| 40 | #define TWO 2 |
| 41 | |
Richard Smith | 85b29a4 | 2012-02-17 01:35:32 +0000 | [diff] [blame] | 42 | int test_cond(int y, int fooBar) { // expected-note {{here}} |
Chris Lattner | e5deae9 | 2010-04-20 21:33:39 +0000 | [diff] [blame] | 43 | // CHECK: int x = y ? 1 : 4+fooBar; |
Richard Smith | 85b29a4 | 2012-02-17 01:35:32 +0000 | [diff] [blame] | 44 | int x = y ? 1 4+foobar; // expected-error {{expected ':'}} expected-error {{undeclared identifier}} expected-note {{to match}} |
Argyrios Kyrtzidis | b5303aa | 2011-06-24 17:28:29 +0000 | [diff] [blame] | 45 | // CHECK: x = y ? ONE : TWO; |
Richard Smith | 85b29a4 | 2012-02-17 01:35:32 +0000 | [diff] [blame] | 46 | x = y ? ONE TWO; // expected-error {{':'}} expected-note {{to match}} |
Ted Kremenek | 987aa87 | 2010-04-12 22:10:35 +0000 | [diff] [blame] | 47 | return x; |
| 48 | } |
Douglas Gregor | ae2fb14 | 2010-08-23 14:34:43 +0000 | [diff] [blame] | 49 | |
Richard Smith | 85b29a4 | 2012-02-17 01:35:32 +0000 | [diff] [blame] | 50 | // CHECK: const typedef int int_t; |
| 51 | const typedef typedef int int_t; // expected-warning {{duplicate 'typedef'}} |
Douglas Gregor | 751f692 | 2010-09-07 14:51:08 +0000 | [diff] [blame] | 52 | |
| 53 | // <rdar://problem/7159693> |
| 54 | enum Color { |
| 55 | Red // expected-error{{missing ',' between enumerators}} |
| 56 | Green = 17 // expected-error{{missing ',' between enumerators}} |
| 57 | Blue, |
| 58 | }; |
Argyrios Kyrtzidis | b8a9d3b | 2011-04-21 17:29:47 +0000 | [diff] [blame] | 59 | |
| 60 | // rdar://9295072 |
| 61 | struct test_struct { |
| 62 | // CHECK: struct test_struct *struct_ptr; |
| 63 | test_struct *struct_ptr; // expected-error {{must use 'struct' tag to refer to type 'test_struct'}} |
| 64 | }; |
Anna Zaks | d5612a2 | 2011-07-28 20:52:06 +0000 | [diff] [blame] | 65 | |
| 66 | void removeUnusedLabels(char c) { |
Richard Smith | 85b29a4 | 2012-02-17 01:35:32 +0000 | [diff] [blame] | 67 | L0 /*removed comment*/: c++; // expected-warning {{unused label}} |
Anna Zaks | d5612a2 | 2011-07-28 20:52:06 +0000 | [diff] [blame] | 68 | removeUnusedLabels(c); |
Richard Smith | 85b29a4 | 2012-02-17 01:35:32 +0000 | [diff] [blame] | 69 | L1: // expected-warning {{unused label}} |
Anna Zaks | d5612a2 | 2011-07-28 20:52:06 +0000 | [diff] [blame] | 70 | c++; |
Richard Smith | 85b29a4 | 2012-02-17 01:35:32 +0000 | [diff] [blame] | 71 | /*preserved comment*/ L2 : c++; // expected-warning {{unused label}} |
| 72 | LL // expected-warning {{unused label}} |
Anna Zaks | d5612a2 | 2011-07-28 20:52:06 +0000 | [diff] [blame] | 73 | : c++; |
Richard Smith | 85b29a4 | 2012-02-17 01:35:32 +0000 | [diff] [blame] | 74 | c = c + 3; L4: return; // expected-warning {{unused label}} |
Anna Zaks | d5612a2 | 2011-07-28 20:52:06 +0000 | [diff] [blame] | 75 | } |
Richard Smith | 0706df4 | 2011-10-19 21:33:05 +0000 | [diff] [blame] | 76 | |
Richard Smith | 85b29a4 | 2012-02-17 01:35:32 +0000 | [diff] [blame] | 77 | int oopsAComma = 0, // expected-error {{';'}} |
Richard Smith | 0706df4 | 2011-10-19 21:33:05 +0000 | [diff] [blame] | 78 | void oopsMoreCommas() { |
Richard Smith | 85b29a4 | 2012-02-17 01:35:32 +0000 | [diff] [blame] | 79 | static int a[] = { 0, 1, 2 }, // expected-error {{';'}} |
| 80 | static int b[] = { 3, 4, 5 }, // expected-error {{';'}} |
Richard Smith | 0706df4 | 2011-10-19 21:33:05 +0000 | [diff] [blame] | 81 | &a == &b ? oopsMoreCommas() : removeUnusedLabels(a[0]); |
| 82 | } |
Richard Smith | 85b29a4 | 2012-02-17 01:35:32 +0000 | [diff] [blame] | 83 | |
| 84 | int noSemiAfterLabel(int n) { |
| 85 | switch (n) { |
| 86 | default: |
| 87 | return n % 4; |
| 88 | case 0: |
| 89 | case 1: |
| 90 | case 2: |
| 91 | // CHECK: /*FOO*/ case 3: ; |
| 92 | /*FOO*/ case 3: // expected-error {{expected statement}} |
| 93 | } |
| 94 | switch (n) { |
| 95 | case 1: |
| 96 | case 2: |
| 97 | return 0; |
| 98 | // CHECK: /*BAR*/ default: ; |
| 99 | /*BAR*/ default: // expected-error {{expected statement}} |
| 100 | } |
| 101 | return 1; |
| 102 | } |