blob: aa9f0f146e4cea0540d1f8a6ef0ed33bdb37b9b7 [file] [log] [blame]
Daniel Dunbar1057f862011-03-18 21:23:38 +00001/* Clang supports a very limited subset of -traditional-cpp, basically we only
2 * intend to add support for things that people actually rely on when doing
3 * things like using /usr/bin/cpp to preprocess non-source files. */
4
5/*
Eli Friedmancefc7ea2013-08-28 20:53:32 +00006 RUN: %clang_cc1 -traditional-cpp %s -E | FileCheck -strict-whitespace %s
Jordan Rose67b66232013-03-05 23:54:55 +00007 RUN: %clang_cc1 -traditional-cpp %s -E -C | FileCheck -check-prefix=CHECK-COMMENTS %s
Eli Friedmancefc7ea2013-08-28 20:53:32 +00008 RUN: %clang_cc1 -traditional-cpp -x c++ %s -E | FileCheck -check-prefix=CHECK-CXX %s
Daniel Dunbar1057f862011-03-18 21:23:38 +00009*/
10
Jordan Rose67b66232013-03-05 23:54:55 +000011/* -traditional-cpp should eliminate all C89 comments. */
12/* CHECK-NOT: /*
13 * CHECK-COMMENTS: {{^}}/* -traditional-cpp should eliminate all C89 comments. *{{/$}}
14 */
15
Eli Friedmancefc7ea2013-08-28 20:53:32 +000016/* -traditional-cpp should only eliminate "//" comments in C++ mode. */
Jordan Rosecb8a1ac2013-02-21 18:53:19 +000017/* CHECK: {{^}}foo // bar{{$}}
Eli Friedmancefc7ea2013-08-28 20:53:32 +000018 * CHECK-CXX: {{^}}foo {{$}}
Daniel Dunbar1057f862011-03-18 21:23:38 +000019 */
20foo // bar
Jordan Rosecb8a1ac2013-02-21 18:53:19 +000021
22
23/* The lines in this file contain hard tab characters and trailing whitespace;
24 * do not change them! */
25
26/* CHECK: {{^}} indented!{{$}}
27 * CHECK: {{^}}tab separated values{{$}}
28 */
29 indented!
30tab separated values
31
32#define bracket(x) >>>x<<<
33bracket(| spaces |)
34/* CHECK: {{^}}>>>| spaces |<<<{{$}}
35 */
36
37/* This is still a preprocessing directive. */
38# define foo bar
39foo!
40-
41 foo! foo!
42/* CHECK: {{^}}bar!{{$}}
43 * CHECK: {{^}} bar! bar! {{$}}
44 */
45
46/* Deliberately check a leading newline with spaces on that line. */
47
48# define foo bar
49foo!
50-
51 foo! foo!
52/* CHECK: {{^}}bar!{{$}}
53 * CHECK: {{^}} bar! bar! {{$}}
54 */
55
56/* FIXME: -traditional-cpp should not consider this a preprocessing directive
57 * because the # isn't in the first column.
58 */
59 #define foo2 bar
60foo2!
61/* If this were working, both of these checks would be on.
62 * CHECK-NOT: {{^}} #define foo2 bar{{$}}
63 * CHECK-NOT: {{^}}foo2!{{$}}
64 */
65
66/* FIXME: -traditional-cpp should not homogenize whitespace in macros.
67 */
68#define bracket2(x) >>> x <<<
69bracket2(spaces)
70/* If this were working, this check would be on.
71 * CHECK-NOT: {{^}}>>> spaces <<<{{$}}
72 */
Jordan Rose176057b2013-02-22 00:32:00 +000073
74
75/* Check that #if 0 blocks work as expected */
76#if 0
77#error "this is not an error"
78
79#if 1
80a b c in skipped block
81#endif
82
83/* Comments are whitespace too */
84
85#endif
86/* CHECK-NOT: {{^}}a b c in skipped block{{$}}
87 * CHECK-NOT: {{^}}/* Comments are whitespace too
88 */
Jordan Rose864b8102013-03-05 22:51:04 +000089
90Preserve URLs: http://clang.llvm.org
91/* CHECK: {{^}}Preserve URLs: http://clang.llvm.org{{$}}
92 */
Richard Smith701a3522013-07-09 01:00:29 +000093
94/* The following tests ensure we ignore # and ## in macro bodies */
95
96#define FOO_NO_STRINGIFY(a) test(# a)
97FOO_NO_STRINGIFY(foobar)
98/* CHECK: {{^}}test(# foobar){{$}}
99 */
100
101#define FOO_NO_PASTE(a, b) test(b##a)
102FOO_NO_PASTE(foo,bar)
103/* CHECK {{^}}test(bar##foo){{$}}
104 */
105
106#define BAR_NO_STRINGIFY(a) test(#a)
107BAR_NO_STRINGIFY(foobar)
108/* CHECK: {{^}}test(#foobar){{$}}
109 */