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