blob: 5ba0aac4509b667e9e4fc50edf5c59ae76325d4a [file] [log] [blame]
Nick Lewyckyba5f6ec2010-04-24 01:30:46 +00001// RUN: cp %s %t
Richard Smith23153182011-09-06 03:01:15 +00002// RUN: not %clang_cc1 -pedantic -Wunused-label -fixit -x c %t
Nick Lewyckyba5f6ec2010-04-24 01:30:46 +00003// RUN: grep -v CHECK %t > %t2
Anna Zaksd5612a22011-07-28 20:52:06 +00004// RUN: %clang_cc1 -pedantic -Wunused-label -Werror -x c %t
Nick Lewyckyba5f6ec2010-04-24 01:30:46 +00005// RUN: FileCheck -input-file=%t2 %t
Douglas Gregor9b3064b2009-04-01 22:41:11 +00006
7/* This is a test of the various code modification hints that are
Douglas Gregorfe057ac2009-04-02 03:20:30 +00008 provided as part of warning or extension diagnostics. All of the
9 warnings will be fixed by -fixit, and the resulting file should
10 compile cleanly with -Werror -pedantic. */
Daniel Dunbard8aefab2009-11-17 22:25:16 +000011
12// FIXME: FIX-IT should add #include <string.h>?
13int strcmp(const char *s1, const char *s2);
Douglas Gregor9b3064b2009-04-01 22:41:11 +000014
15void f0(void) { };
16
17struct s {
18 int x, y;;
19};
20
Daniel Dunbar266cc532009-11-14 19:25:21 +000021// CHECK: _Complex double cd;
Douglas Gregor9b3064b2009-04-01 22:41:11 +000022_Complex cd;
23
Daniel Dunbar266cc532009-11-14 19:25:21 +000024// CHECK: struct s s0 = { .y = 5 };
Douglas Gregor9b3064b2009-04-01 22:41:11 +000025struct s s0 = { y: 5 };
Daniel Dunbar266cc532009-11-14 19:25:21 +000026
27// CHECK: int array0[5] = { [3] = 3 };
Douglas Gregor9b3064b2009-04-01 22:41:11 +000028int array0[5] = { [3] 3 };
Douglas Gregora3a83512009-04-01 23:51:29 +000029
Nick Lewyckyba5f6ec2010-04-24 01:30:46 +000030void f1(x, y)
Douglas Gregora3a83512009-04-01 23:51:29 +000031{
32}
33
34int i0 = { 17 };
35
Argyrios Kyrtzidisb5303aa2011-06-24 17:28:29 +000036#define ONE 1
37#define TWO 2
38
Chris Lattnere5deae92010-04-20 21:33:39 +000039int test_cond(int y, int fooBar) {
40// CHECK: int x = y ? 1 : 4+fooBar;
41 int x = y ? 1 4+foobar;
Argyrios Kyrtzidisb5303aa2011-06-24 17:28:29 +000042// CHECK: x = y ? ONE : TWO;
43 x = y ? ONE TWO;
Ted Kremenek987aa872010-04-12 22:10:35 +000044 return x;
45}
Douglas Gregorae2fb142010-08-23 14:34:43 +000046
47// CHECK: typedef int int_t;
48typedef typedef int int_t;
Douglas Gregor751f6922010-09-07 14:51:08 +000049
50// <rdar://problem/7159693>
51enum Color {
52 Red // expected-error{{missing ',' between enumerators}}
53 Green = 17 // expected-error{{missing ',' between enumerators}}
54 Blue,
55};
Argyrios Kyrtzidisb8a9d3b2011-04-21 17:29:47 +000056
57// rdar://9295072
58struct test_struct {
59 // CHECK: struct test_struct *struct_ptr;
60 test_struct *struct_ptr; // expected-error {{must use 'struct' tag to refer to type 'test_struct'}}
61};
Anna Zaksd5612a22011-07-28 20:52:06 +000062
63void removeUnusedLabels(char c) {
64 L0 /*removed comment*/: c++;
65 removeUnusedLabels(c);
66 L1:
67 c++;
68 /*preserved comment*/ L2 : c++;
69 LL
70 : c++;
71 c = c + 3; L4: return;
72}