annotate clang/test/Preprocessor/traditional-cpp.c @ 236:c4bab56944e8 llvm-original

LLVM 16
author kono
date Wed, 09 Nov 2022 17:45:10 +0900
parents 1d019706d866
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 /* Clang supports a very limited subset of -traditional-cpp, basically we only
anatofuz
parents:
diff changeset
2 * intend to add support for things that people actually rely on when doing
anatofuz
parents:
diff changeset
3 * things like using /usr/bin/cpp to preprocess non-source files. */
anatofuz
parents:
diff changeset
4
anatofuz
parents:
diff changeset
5 /*
anatofuz
parents:
diff changeset
6 RUN: %clang_cc1 -traditional-cpp %s -E | FileCheck -strict-whitespace %s
anatofuz
parents:
diff changeset
7 RUN: %clang_cc1 -traditional-cpp %s -E -C | FileCheck -check-prefix=CHECK-COMMENTS %s
anatofuz
parents:
diff changeset
8 RUN: %clang_cc1 -traditional-cpp -x c++ %s -E | FileCheck -check-prefix=CHECK-CXX %s
anatofuz
parents:
diff changeset
9 */
anatofuz
parents:
diff changeset
10
anatofuz
parents:
diff changeset
11 /* -traditional-cpp should eliminate all C89 comments. */
anatofuz
parents:
diff changeset
12 /* CHECK-NOT: /*
anatofuz
parents:
diff changeset
13 * CHECK-COMMENTS: {{^}}/* -traditional-cpp should eliminate all C89 comments. *{{/$}}
anatofuz
parents:
diff changeset
14 */
anatofuz
parents:
diff changeset
15
anatofuz
parents:
diff changeset
16 /* -traditional-cpp should only eliminate "//" comments in C++ mode. */
anatofuz
parents:
diff changeset
17 /* CHECK: {{^}}foo // bar{{$}}
anatofuz
parents:
diff changeset
18 * CHECK-CXX: {{^}}foo {{$}}
anatofuz
parents:
diff changeset
19 */
anatofuz
parents:
diff changeset
20 foo // bar
anatofuz
parents:
diff changeset
21
anatofuz
parents:
diff changeset
22
anatofuz
parents:
diff changeset
23 /* The lines in this file contain hard tab characters and trailing whitespace;
anatofuz
parents:
diff changeset
24 * do not change them! */
anatofuz
parents:
diff changeset
25
anatofuz
parents:
diff changeset
26 /* CHECK: {{^}} indented!{{$}}
anatofuz
parents:
diff changeset
27 * CHECK: {{^}}tab separated values{{$}}
anatofuz
parents:
diff changeset
28 */
anatofuz
parents:
diff changeset
29 indented!
anatofuz
parents:
diff changeset
30 tab separated values
anatofuz
parents:
diff changeset
31
anatofuz
parents:
diff changeset
32 #define bracket(x) >>>x<<<
anatofuz
parents:
diff changeset
33 bracket(| spaces |)
anatofuz
parents:
diff changeset
34 /* CHECK: {{^}}>>>| spaces |<<<{{$}}
anatofuz
parents:
diff changeset
35 */
anatofuz
parents:
diff changeset
36
anatofuz
parents:
diff changeset
37 /* This is still a preprocessing directive. */
anatofuz
parents:
diff changeset
38 # define foo bar
anatofuz
parents:
diff changeset
39 foo!
anatofuz
parents:
diff changeset
40 -
anatofuz
parents:
diff changeset
41 foo! foo!
anatofuz
parents:
diff changeset
42 /* CHECK: {{^}}bar!{{$}}
anatofuz
parents:
diff changeset
43 * CHECK: {{^}} bar! bar! {{$}}
anatofuz
parents:
diff changeset
44 */
anatofuz
parents:
diff changeset
45
anatofuz
parents:
diff changeset
46 /* Deliberately check a leading newline with spaces on that line. */
anatofuz
parents:
diff changeset
47
anatofuz
parents:
diff changeset
48 # define foo bar
anatofuz
parents:
diff changeset
49 foo!
anatofuz
parents:
diff changeset
50 -
anatofuz
parents:
diff changeset
51 foo! foo!
anatofuz
parents:
diff changeset
52 /* CHECK: {{^}}bar!{{$}}
anatofuz
parents:
diff changeset
53 * CHECK: {{^}} bar! bar! {{$}}
anatofuz
parents:
diff changeset
54 */
anatofuz
parents:
diff changeset
55
anatofuz
parents:
diff changeset
56 /* FIXME: -traditional-cpp should not consider this a preprocessing directive
anatofuz
parents:
diff changeset
57 * because the # isn't in the first column.
anatofuz
parents:
diff changeset
58 */
anatofuz
parents:
diff changeset
59 #define foo2 bar
anatofuz
parents:
diff changeset
60 foo2!
anatofuz
parents:
diff changeset
61 /* If this were working, both of these checks would be on.
anatofuz
parents:
diff changeset
62 * CHECK-NOT: {{^}} #define foo2 bar{{$}}
anatofuz
parents:
diff changeset
63 * CHECK-NOT: {{^}}foo2!{{$}}
anatofuz
parents:
diff changeset
64 */
anatofuz
parents:
diff changeset
65
anatofuz
parents:
diff changeset
66 /* FIXME: -traditional-cpp should not homogenize whitespace in macros.
anatofuz
parents:
diff changeset
67 */
anatofuz
parents:
diff changeset
68 #define bracket2(x) >>> x <<<
anatofuz
parents:
diff changeset
69 bracket2(spaces)
anatofuz
parents:
diff changeset
70 /* If this were working, this check would be on.
anatofuz
parents:
diff changeset
71 * CHECK-NOT: {{^}}>>> spaces <<<{{$}}
anatofuz
parents:
diff changeset
72 */
anatofuz
parents:
diff changeset
73
anatofuz
parents:
diff changeset
74
anatofuz
parents:
diff changeset
75 /* Check that #if 0 blocks work as expected */
anatofuz
parents:
diff changeset
76 #if 0
anatofuz
parents:
diff changeset
77 #error "this is not an error"
anatofuz
parents:
diff changeset
78
anatofuz
parents:
diff changeset
79 #if 1
anatofuz
parents:
diff changeset
80 a b c in skipped block
anatofuz
parents:
diff changeset
81 #endif
anatofuz
parents:
diff changeset
82
anatofuz
parents:
diff changeset
83 /* Comments are whitespace too */
anatofuz
parents:
diff changeset
84
anatofuz
parents:
diff changeset
85 #endif
anatofuz
parents:
diff changeset
86 /* CHECK-NOT: {{^}}a b c in skipped block{{$}}
anatofuz
parents:
diff changeset
87 * CHECK-NOT: {{^}}/* Comments are whitespace too
anatofuz
parents:
diff changeset
88 */
anatofuz
parents:
diff changeset
89
anatofuz
parents:
diff changeset
90 Preserve URLs: http://clang.llvm.org
anatofuz
parents:
diff changeset
91 /* CHECK: {{^}}Preserve URLs: http://clang.llvm.org{{$}}
anatofuz
parents:
diff changeset
92 */
anatofuz
parents:
diff changeset
93
anatofuz
parents:
diff changeset
94 /* The following tests ensure we ignore # and ## in macro bodies */
anatofuz
parents:
diff changeset
95
anatofuz
parents:
diff changeset
96 #define FOO_NO_STRINGIFY(a) test(# a)
anatofuz
parents:
diff changeset
97 FOO_NO_STRINGIFY(foobar)
anatofuz
parents:
diff changeset
98 /* CHECK: {{^}}test(# foobar){{$}}
anatofuz
parents:
diff changeset
99 */
anatofuz
parents:
diff changeset
100
anatofuz
parents:
diff changeset
101 #define FOO_NO_PASTE(a, b) test(b##a)
anatofuz
parents:
diff changeset
102 FOO_NO_PASTE(xxx,yyy)
anatofuz
parents:
diff changeset
103 /* CHECK: {{^}}test(yyy##xxx){{$}}
anatofuz
parents:
diff changeset
104 */
anatofuz
parents:
diff changeset
105
anatofuz
parents:
diff changeset
106 #define BAR_NO_STRINGIFY(a) test(#a)
anatofuz
parents:
diff changeset
107 BAR_NO_STRINGIFY(foobar)
anatofuz
parents:
diff changeset
108 /* CHECK: {{^}}test(#foobar){{$}}
anatofuz
parents:
diff changeset
109 */