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: grep -v CHECK %t > %t2
5// RUN: %clang_cc1 -pedantic -Wunused-label -Werror -x c %t
6// RUN: FileCheck -input-file=%t2 %t
7
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. */
12
13// FIXME: FIX-IT should add #include <string.h>?
14int strcmp(const char *s1, const char *s2);
15
16void f0(void) { }; // expected-warning {{';'}}
17
18struct s {
19  int x, y;; // expected-warning {{extra ';'}}
20};
21
22// CHECK: _Complex double cd;
23_Complex cd; // expected-warning {{assuming '_Complex double'}}
24
25// CHECK: struct s s0 = { .y = 5 };
26struct s s0 = { y: 5 }; // expected-warning {{GNU old-style}}
27
28// CHECK: int array0[5] = { [3] = 3 };
29int array0[5] = { [3] 3 }; // expected-warning {{GNU 'missing ='}}
30
31// CHECK: int x
32// CHECK: int y
33void f1(x, y) // expected-warning 2{{defaulting to type 'int'}}
34{
35}
36
37int i0 = { 17 };
38
39#define ONE 1
40#define TWO 2
41
42int 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}}
47  return x;
48}
49
50// CHECK: const typedef int int_t;
51const typedef typedef int int_t; // expected-warning {{duplicate 'typedef'}}
52
53// <rdar://problem/7159693>
54enum Color {
55  Red // expected-error{{missing ',' between enumerators}}
56  Green = 17 // expected-error{{missing ',' between enumerators}}
57  Blue,
58};
59
60// rdar://9295072
61struct test_struct {
62  // CHECK: struct test_struct *struct_ptr;
63  test_struct *struct_ptr; // expected-error {{must use 'struct' tag to refer to type 'test_struct'}}
64};
65
66void removeUnusedLabels(char c) {
67  L0 /*removed comment*/:        c++; // expected-warning {{unused label}}
68  removeUnusedLabels(c);
69  L1: // expected-warning {{unused label}}
70  c++;
71  /*preserved comment*/ L2  :        c++; // expected-warning {{unused label}}
72  LL // expected-warning {{unused label}}
73  : c++;
74  c = c + 3; L4: return; // expected-warning {{unused label}}
75}
76
77int oopsAComma = 0, // expected-error {{';'}}
78void 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]);
82}
83
84int noSemiAfterLabel(int n) {
85  switch (n) {
86    default:
87      return n % 4;
88    case 0:
89    case 1:
90    case 2:
91    // CHECK: /*FOO*/ case 3: ;
92    /*FOO*/ case 3: // expected-error {{expected statement}}
93  }
94  switch (n) {
95    case 1:
96    case 2:
97      return 0;
98    // CHECK: /*BAR*/ default: ;
99    /*BAR*/ default: // expected-error {{expected statement}}
100  }
101  return 1;
102}
103
104struct noSemiAfterStruct // expected-error {{expected ';' after struct}}
105struct noSemiAfterStruct {
106  int n // expected-warning {{';'}}
107} // expected-error {{expected ';' after struct}}
108enum noSemiAfterEnum {
109  e1
110} // expected-error {{expected ';' after enum}}
111