| 1 | // RUN: %clang_cc1 -pedantic -Wunused-label -verify -x c %s |
| 2 | // RUN: cp %s %t |
| 3 | // RUN: not %clang_cc1 -pedantic -Wunused-label -fixit -x c %t |
| 4 | // RUN: %clang_cc1 -pedantic -Wunused-label -Werror -x c %t |
| 5 | // RUN: grep -v CHECK %t | FileCheck %t |
| 6 | |
| 7 | /* This is a test of the various code modification hints that are |
| 8 | provided as part of warning or extension diagnostics. All of the |
| 9 | warnings will be fixed by -fixit, and the resulting file should |
| 10 | compile cleanly with -Werror -pedantic. */ |
| 11 | |
| 12 | // FIXME: FIX-IT should add #include <string.h>? |
| 13 | int strcmp(const char *s1, const char *s2); |
| 14 | |
| 15 | void f0(void) { }; // expected-warning {{';'}} |
| 16 | |
| 17 | struct s { |
| 18 | int x, y;; // expected-warning {{extra ';'}} |
| 19 | }; |
| 20 | |
| 21 | // CHECK: _Complex double cd; |
| 22 | _Complex cd; // expected-warning {{assuming '_Complex double'}} |
| 23 | |
| 24 | // CHECK: struct s s0 = { .y = 5 }; |
| 25 | struct s s0 = { y: 5 }; // expected-warning {{GNU old-style}} |
| 26 | |
| 27 | // CHECK: int array0[5] = { [3] = 3 }; |
| 28 | int array0[5] = { [3] 3 }; // expected-warning {{GNU 'missing ='}} |
| 29 | |
| 30 | // CHECK: int x |
| 31 | // CHECK: int y |
| 32 | void f1(x, y) // expected-warning 2{{defaulting to type 'int'}} |
| 33 | { |
| 34 | } |
| 35 | |
| 36 | int i0 = { 17 }; |
| 37 | |
| 38 | #define ONE 1 |
| 39 | #define TWO 2 |
| 40 | |
| 41 | int test_cond(int y, int fooBar) { // expected-note {{here}} |
| 42 | // CHECK: int x = y ? 1 : 4+fooBar; |
| 43 | int x = y ? 1 4+foobar; // expected-error {{expected ':'}} expected-error {{undeclared identifier}} expected-note {{to match}} |
| 44 | // CHECK: x = y ? ONE : TWO; |
| 45 | x = y ? ONE TWO; // expected-error {{':'}} expected-note {{to match}} |
| 46 | return x; |
| 47 | } |
| 48 | |
| 49 | // CHECK: const typedef int int_t; |
| 50 | const typedef typedef int int_t; // expected-warning {{duplicate 'typedef'}} |
| 51 | |
| 52 | // <rdar://problem/7159693> |
| 53 | enum Color { |
| 54 | Red // expected-error{{missing ',' between enumerators}} |
| 55 | Green = 17 // expected-error{{missing ',' between enumerators}} |
| 56 | Blue, |
| 57 | }; |
| 58 | |
| 59 | // rdar://9295072 |
| 60 | struct test_struct { |
| 61 | // CHECK: struct test_struct *struct_ptr; |
| 62 | test_struct *struct_ptr; // expected-error {{must use 'struct' tag to refer to type 'test_struct'}} |
| 63 | }; |
| 64 | |
| 65 | void removeUnusedLabels(char c) { |
| 66 | L0 /*removed comment*/: c++; // expected-warning {{unused label}} |
| 67 | removeUnusedLabels(c); |
| 68 | L1: // expected-warning {{unused label}} |
| 69 | c++; |
| 70 | /*preserved comment*/ L2 : c++; // expected-warning {{unused label}} |
| 71 | LL // expected-warning {{unused label}} |
| 72 | : c++; |
| 73 | c = c + 3; L4: return; // expected-warning {{unused label}} |
| 74 | } |
| 75 | |
| 76 | int oopsAComma = 0, // expected-error {{';'}} |
| 77 | void oopsMoreCommas() { |
| 78 | static int a[] = { 0, 1, 2 }, // expected-error {{';'}} |
| 79 | static int b[] = { 3, 4, 5 }, // expected-error {{';'}} |
| 80 | &a == &b ? oopsMoreCommas() : removeUnusedLabels(a[0]); |
| 81 | } |
| 82 | |
| 83 | int commaAtEndOfStatement() { |
| 84 | int a = 1; |
| 85 | a = 5, // expected-error {{';'}} |
| 86 | int m = 5, // expected-error {{';'}} |
| 87 | return 0, // expected-error {{';'}} |
| 88 | } |
| 89 | |
| 90 | int noSemiAfterLabel(int n) { |
| 91 | switch (n) { |
| 92 | default: |
| 93 | return n % 4; |
| 94 | case 0: |
| 95 | case 1: |
| 96 | case 2: |
| 97 | // CHECK: /*FOO*/ case 3: ; |
| 98 | /*FOO*/ case 3: // expected-error {{expected statement}} |
| 99 | } |
| 100 | switch (n) { |
| 101 | case 1: |
| 102 | case 2: |
| 103 | return 0; |
| 104 | // CHECK: /*BAR*/ default: ; |
| 105 | /*BAR*/ default: // expected-error {{expected statement}} |
| 106 | } |
| 107 | return 1; |
| 108 | } |
| 109 | |
| 110 | struct noSemiAfterStruct // expected-error {{expected ';' after struct}} |
| 111 | struct noSemiAfterStruct { |
| 112 | int n // expected-warning {{';'}} |
| 113 | } // expected-error {{expected ';' after struct}} |
| 114 | enum noSemiAfterEnum { |
| 115 | e1 |
| 116 | } // expected-error {{expected ';' after enum}} |
| 117 | |
| 118 | int PR17175 __attribute__((visibility(hidden))); // expected-error {{'visibility' attribute requires a string}} |
| 119 | |