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