blob: b8bb99d93cbb96216ccf97827ccbcd71f2a4dd9c [file] [log] [blame]
Daniel Dunbar2ed42282011-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/*
6 RUN: %clang_cc1 -traditional-cpp %s -E -o %t
Jordan Rose6aad4a32013-02-21 18:53:19 +00007 RUN: FileCheck -strict-whitespace < %t %s
Jordan Rosecf2c2e92013-03-05 23:54:55 +00008 RUN: %clang_cc1 -traditional-cpp %s -E -C | FileCheck -check-prefix=CHECK-COMMENTS %s
Daniel Dunbar2ed42282011-03-18 21:23:38 +00009*/
10
Jordan Rosecf2c2e92013-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
Jordan Rose6aad4a32013-02-21 18:53:19 +000016/* CHECK: {{^}}foo // bar{{$}}
Daniel Dunbar2ed42282011-03-18 21:23:38 +000017 */
18foo // bar
Jordan Rose6aad4a32013-02-21 18:53:19 +000019
20
21/* The lines in this file contain hard tab characters and trailing whitespace;
22 * do not change them! */
23
24/* CHECK: {{^}} indented!{{$}}
25 * CHECK: {{^}}tab separated values{{$}}
26 */
27 indented!
28tab separated values
29
30#define bracket(x) >>>x<<<
31bracket(| spaces |)
32/* CHECK: {{^}}>>>| spaces |<<<{{$}}
33 */
34
35/* This is still a preprocessing directive. */
36# define foo bar
37foo!
38-
39 foo! foo!
40/* CHECK: {{^}}bar!{{$}}
41 * CHECK: {{^}} bar! bar! {{$}}
42 */
43
44/* Deliberately check a leading newline with spaces on that line. */
45
46# define foo bar
47foo!
48-
49 foo! foo!
50/* CHECK: {{^}}bar!{{$}}
51 * CHECK: {{^}} bar! bar! {{$}}
52 */
53
54/* FIXME: -traditional-cpp should not consider this a preprocessing directive
55 * because the # isn't in the first column.
56 */
57 #define foo2 bar
58foo2!
59/* If this were working, both of these checks would be on.
60 * CHECK-NOT: {{^}} #define foo2 bar{{$}}
61 * CHECK-NOT: {{^}}foo2!{{$}}
62 */
63
64/* FIXME: -traditional-cpp should not homogenize whitespace in macros.
65 */
66#define bracket2(x) >>> x <<<
67bracket2(spaces)
68/* If this were working, this check would be on.
69 * CHECK-NOT: {{^}}>>> spaces <<<{{$}}
70 */
Jordan Rosec7d1ca52013-02-22 00:32:00 +000071
72
73/* Check that #if 0 blocks work as expected */
74#if 0
75#error "this is not an error"
76
77#if 1
78a b c in skipped block
79#endif
80
81/* Comments are whitespace too */
82
83#endif
84/* CHECK-NOT: {{^}}a b c in skipped block{{$}}
85 * CHECK-NOT: {{^}}/* Comments are whitespace too
86 */
Jordan Rose693fdfa2013-03-05 22:51:04 +000087
88Preserve URLs: http://clang.llvm.org
89/* CHECK: {{^}}Preserve URLs: http://clang.llvm.org{{$}}
90 */
Richard Smithbd89fdc2013-07-09 01:00:29 +000091
92/* The following tests ensure we ignore # and ## in macro bodies */
93
94#define FOO_NO_STRINGIFY(a) test(# a)
95FOO_NO_STRINGIFY(foobar)
96/* CHECK: {{^}}test(# foobar){{$}}
97 */
98
99#define FOO_NO_PASTE(a, b) test(b##a)
100FOO_NO_PASTE(foo,bar)
101/* CHECK {{^}}test(bar##foo){{$}}
102 */
103
104#define BAR_NO_STRINGIFY(a) test(#a)
105BAR_NO_STRINGIFY(foobar)
106/* CHECK: {{^}}test(#foobar){{$}}
107 */