1 // RUN: %clang_cc1 -pedantic -Wunused-label -verify -x c %s
3 // RUN: not %clang_cc1 -pedantic -Wunused-label -fixit -x c %t
4 // RUN: grep -v CHECK %t > %t2
5 // RUN: %clang_cc1 -pedantic -Wunused-label -Werror -x c %t
6 // RUN: FileCheck -input-file=%t2 %t
8 /* This is a test of the various code modification hints that are
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. */
13 // FIXME: FIX-IT should add #include <string.h>?
14 int strcmp(const char *s1, const char *s2);
16 void f0(void) { }; // expected-warning {{';'}}
19 int x, y;; // expected-warning {{extra ';'}}
22 // CHECK: _Complex double cd;
23 _Complex cd; // expected-warning {{assuming '_Complex double'}}
25 // CHECK: struct s s0 = { .y = 5 };
26 struct s s0 = { y: 5 }; // expected-warning {{GNU old-style}}
28 // CHECK: int array0[5] = { [3] = 3 };
29 int array0[5] = { [3] 3 }; // expected-warning {{GNU 'missing ='}}
33 void f1(x, y) // expected-warning 2{{defaulting to type 'int'}}
42 int test_cond(int y, int fooBar) { // expected-note {{here}}
43 // CHECK: int x = y ? 1 : 4+fooBar;
44 int x = y ? 1 4+foobar; // expected-error {{expected ':'}} expected-error {{undeclared identifier}} expected-note {{to match}}
45 // CHECK: x = y ? ONE : TWO;
46 x = y ? ONE TWO; // expected-error {{':'}} expected-note {{to match}}
50 // CHECK: const typedef int int_t;
51 const typedef typedef int int_t; // expected-warning {{duplicate 'typedef'}}
53 // <rdar://problem/7159693>
55 Red // expected-error{{missing ',' between enumerators}}
56 Green = 17 // expected-error{{missing ',' between enumerators}}
62 // CHECK: struct test_struct *struct_ptr;
63 test_struct *struct_ptr; // expected-error {{must use 'struct' tag to refer to type 'test_struct'}}
66 void removeUnusedLabels(char c) {
67 L0 /*removed comment*/: c++; // expected-warning {{unused label}}
68 removeUnusedLabels(c);
69 L1: // expected-warning {{unused label}}
71 /*preserved comment*/ L2 : c++; // expected-warning {{unused label}}
72 LL // expected-warning {{unused label}}
74 c = c + 3; L4: return; // expected-warning {{unused label}}
77 int oopsAComma = 0, // expected-error {{';'}}
78 void oopsMoreCommas() {
79 static int a[] = { 0, 1, 2 }, // expected-error {{';'}}
80 static int b[] = { 3, 4, 5 }, // expected-error {{';'}}
81 &a == &b ? oopsMoreCommas() : removeUnusedLabels(a[0]);
84 int commaAtEndOfStatement() {
86 a = 5, // expected-error {{';'}}
87 int m = 5, // expected-error {{';'}}
88 return 0, // expected-error {{';'}}
91 int noSemiAfterLabel(int n) {
98 // CHECK: /*FOO*/ case 3: ;
99 /*FOO*/ case 3: // expected-error {{expected statement}}
105 // CHECK: /*BAR*/ default: ;
106 /*BAR*/ default: // expected-error {{expected statement}}
111 struct noSemiAfterStruct // expected-error {{expected ';' after struct}}
112 struct noSemiAfterStruct {
113 int n // expected-warning {{';'}}
114 } // expected-error {{expected ';' after struct}}
115 enum noSemiAfterEnum {
117 } // expected-error {{expected ';' after enum}}
119 int PR17175 __attribute__((visibility(hidden))); // expected-error {{'visibility' attribute requires a string}}