• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* 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
7  RUN: FileCheck -strict-whitespace < %t %s
8  RUN: %clang_cc1 -traditional-cpp %s -E -C | FileCheck -check-prefix=CHECK-COMMENTS %s
9 */
10 
11 /* -traditional-cpp should eliminate all C89 comments. */
12 /* CHECK-NOT: /*
13  * CHECK-COMMENTS: {{^}}/* -traditional-cpp should eliminate all C89 comments. *{{/$}}
14  */
15 
16 /* CHECK: {{^}}foo // bar{{$}}
17  */
18 foo // bar
19 
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!
28 tab	separated	values
29 
30 #define bracket(x) >>>x<<<
31 bracket(|  spaces  |)
32 /* CHECK: {{^}}>>>|  spaces  |<<<{{$}}
33  */
34 
35 /* This is still a preprocessing directive. */
36 # define foo bar
37 foo!
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
47 foo!
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
58 foo2!
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  <<<
67 bracket2(spaces)
68 /* If this were working, this check would be on.
69  * CHECK-NOT: {{^}}>>>  spaces  <<<{{$}}
70  */
71 
72 
73 /* Check that #if 0 blocks work as expected */
74 #if 0
75 #error "this is not an error"
76 
77 #if 1
78 a 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  */
87 
88 Preserve URLs: http://clang.llvm.org
89 /* CHECK: {{^}}Preserve URLs: http://clang.llvm.org{{$}}
90  */
91 
92 /* The following tests ensure we ignore # and ## in macro bodies */
93 
94 #define FOO_NO_STRINGIFY(a) test(# a)
95 FOO_NO_STRINGIFY(foobar)
96 /* CHECK: {{^}}test(# foobar){{$}}
97  */
98 
99 #define FOO_NO_PASTE(a, b) test(b##a)
100 FOO_NO_PASTE(foo,bar)
101 /* CHECK {{^}}test(bar##foo){{$}}
102  */
103 
104 #define BAR_NO_STRINGIFY(a) test(#a)
105 BAR_NO_STRINGIFY(foobar)
106 /* CHECK: {{^}}test(#foobar){{$}}
107  */
108