summaryrefslogtreecommitdiffstats
path: root/test/FixIt/fixit.c
blob: ce6f1092df197b046eb5f07d5b62306fafb2c93c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// RUN: %clang_cc1 -pedantic -Wunused-label -verify -x c %s
// RUN: cp %s %t
// RUN: not %clang_cc1 -pedantic -Wunused-label -fixit -x c %t
// RUN: grep -v CHECK %t > %t2
// RUN: %clang_cc1 -pedantic -Wunused-label -Werror -x c %t
// RUN: FileCheck -input-file=%t2 %t

/* This is a test of the various code modification hints that are
   provided as part of warning or extension diagnostics. All of the
   warnings will be fixed by -fixit, and the resulting file should
   compile cleanly with -Werror -pedantic. */

// FIXME: FIX-IT should add #include <string.h>?
int strcmp(const char *s1, const char *s2);

void f0(void) { }; // expected-warning {{';'}}

struct s {
  int x, y;; // expected-warning {{extra ';'}}
};

// CHECK: _Complex double cd;
_Complex cd; // expected-warning {{assuming '_Complex double'}}

// CHECK: struct s s0 = { .y = 5 };
struct s s0 = { y: 5 }; // expected-warning {{GNU old-style}}

// CHECK: int array0[5] = { [3] = 3 };
int array0[5] = { [3] 3 }; // expected-warning {{GNU 'missing ='}}

// CHECK: int x
// CHECK: int y
void f1(x, y) // expected-warning 2{{defaulting to type 'int'}}
{
}

int i0 = { 17 };

#define ONE 1
#define TWO 2

int test_cond(int y, int fooBar) { // expected-note {{here}}
// CHECK: int x = y ? 1 : 4+fooBar;
  int x = y ? 1 4+foobar; // expected-error {{expected ':'}} expected-error {{undeclared identifier}} expected-note {{to match}}
// CHECK: x = y ? ONE : TWO;
  x = y ? ONE TWO; // expected-error {{':'}} expected-note {{to match}}
  return x;
}

// CHECK: const typedef int int_t;
const typedef typedef int int_t; // expected-warning {{duplicate 'typedef'}}

// <rdar://problem/7159693>
enum Color { 
  Red // expected-error{{missing ',' between enumerators}}
  Green = 17 // expected-error{{missing ',' between enumerators}}
  Blue,
};

// rdar://9295072
struct test_struct {
  // CHECK: struct test_struct *struct_ptr;
  test_struct *struct_ptr; // expected-error {{must use 'struct' tag to refer to type 'test_struct'}}
};

void removeUnusedLabels(char c) {
  L0 /*removed comment*/:        c++; // expected-warning {{unused label}}
  removeUnusedLabels(c);
  L1: // expected-warning {{unused label}}
  c++;
  /*preserved comment*/ L2  :        c++; // expected-warning {{unused label}}
  LL // expected-warning {{unused label}}
  : c++;
  c = c + 3; L4: return; // expected-warning {{unused label}}
}

int oopsAComma = 0, // expected-error {{';'}}
void oopsMoreCommas() {
  static int a[] = { 0, 1, 2 }, // expected-error {{';'}}
  static int b[] = { 3, 4, 5 }, // expected-error {{';'}}
  &a == &b ? oopsMoreCommas() : removeUnusedLabels(a[0]);
}

int noSemiAfterLabel(int n) {
  switch (n) {
    default:
      return n % 4;
    case 0:
    case 1:
    case 2:
    // CHECK: /*FOO*/ case 3: ;
    /*FOO*/ case 3: // expected-error {{expected statement}}
  }
  switch (n) {
    case 1:
    case 2:
      return 0;
    // CHECK: /*BAR*/ default: ;
    /*BAR*/ default: // expected-error {{expected statement}}
  }
  return 1;
}

struct noSemiAfterStruct // expected-error {{expected ';' after struct}}
struct noSemiAfterStruct {
  int n // expected-warning {{';'}}
} // expected-error {{expected ';' after struct}}
enum noSemiAfterEnum {
  e1
} // expected-error {{expected ';' after enum}}
OpenPOWER on IntegriCloud