Daniel Dunbar | 1057f86 | 2011-03-18 21:23:38 +0000 | [diff] [blame] | 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 | /* |
Eli Friedman | cefc7ea | 2013-08-28 20:53:32 +0000 | [diff] [blame] | 6 | RUN: %clang_cc1 -traditional-cpp %s -E | FileCheck -strict-whitespace %s |
Jordan Rose | 67b6623 | 2013-03-05 23:54:55 +0000 | [diff] [blame] | 7 | RUN: %clang_cc1 -traditional-cpp %s -E -C | FileCheck -check-prefix=CHECK-COMMENTS %s |
Eli Friedman | cefc7ea | 2013-08-28 20:53:32 +0000 | [diff] [blame] | 8 | RUN: %clang_cc1 -traditional-cpp -x c++ %s -E | FileCheck -check-prefix=CHECK-CXX %s |
Daniel Dunbar | 1057f86 | 2011-03-18 21:23:38 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
Jordan Rose | 67b6623 | 2013-03-05 23:54:55 +0000 | [diff] [blame] | 11 | /* -traditional-cpp should eliminate all C89 comments. */ |
| 12 | /* CHECK-NOT: /* |
| 13 | * CHECK-COMMENTS: {{^}}/* -traditional-cpp should eliminate all C89 comments. *{{/$}} |
| 14 | */ |
| 15 | |
Eli Friedman | cefc7ea | 2013-08-28 20:53:32 +0000 | [diff] [blame] | 16 | /* -traditional-cpp should only eliminate "//" comments in C++ mode. */ |
Jordan Rose | cb8a1ac | 2013-02-21 18:53:19 +0000 | [diff] [blame] | 17 | /* CHECK: {{^}}foo // bar{{$}} |
Eli Friedman | cefc7ea | 2013-08-28 20:53:32 +0000 | [diff] [blame] | 18 | * CHECK-CXX: {{^}}foo {{$}} |
Daniel Dunbar | 1057f86 | 2011-03-18 21:23:38 +0000 | [diff] [blame] | 19 | */ |
| 20 | foo // bar |
Jordan Rose | cb8a1ac | 2013-02-21 18:53:19 +0000 | [diff] [blame] | 21 | |
| 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! |
| 30 | tab separated values |
| 31 | |
| 32 | #define bracket(x) >>>x<<< |
| 33 | bracket(| spaces |) |
| 34 | /* CHECK: {{^}}>>>| spaces |<<<{{$}} |
| 35 | */ |
| 36 | |
| 37 | /* This is still a preprocessing directive. */ |
| 38 | # define foo bar |
| 39 | foo! |
| 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 |
| 49 | foo! |
| 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 |
| 60 | foo2! |
| 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 <<< |
| 69 | bracket2(spaces) |
| 70 | /* If this were working, this check would be on. |
| 71 | * CHECK-NOT: {{^}}>>> spaces <<<{{$}} |
| 72 | */ |
Jordan Rose | 176057b | 2013-02-22 00:32:00 +0000 | [diff] [blame] | 73 | |
| 74 | |
| 75 | /* Check that #if 0 blocks work as expected */ |
| 76 | #if 0 |
| 77 | #error "this is not an error" |
| 78 | |
| 79 | #if 1 |
| 80 | a 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 Rose | 864b810 | 2013-03-05 22:51:04 +0000 | [diff] [blame] | 89 | |
| 90 | Preserve URLs: http://clang.llvm.org |
| 91 | /* CHECK: {{^}}Preserve URLs: http://clang.llvm.org{{$}} |
| 92 | */ |
Richard Smith | 701a352 | 2013-07-09 01:00:29 +0000 | [diff] [blame] | 93 | |
| 94 | /* The following tests ensure we ignore # and ## in macro bodies */ |
| 95 | |
| 96 | #define FOO_NO_STRINGIFY(a) test(# a) |
| 97 | FOO_NO_STRINGIFY(foobar) |
| 98 | /* CHECK: {{^}}test(# foobar){{$}} |
| 99 | */ |
| 100 | |
| 101 | #define FOO_NO_PASTE(a, b) test(b##a) |
Hans Wennborg | 2151d12 | 2015-08-31 21:48:52 +0000 | [diff] [blame] | 102 | FOO_NO_PASTE(xxx,yyy) |
| 103 | /* CHECK: {{^}}test(yyy##xxx){{$}} |
Richard Smith | 701a352 | 2013-07-09 01:00:29 +0000 | [diff] [blame] | 104 | */ |
| 105 | |
| 106 | #define BAR_NO_STRINGIFY(a) test(#a) |
| 107 | BAR_NO_STRINGIFY(foobar) |
| 108 | /* CHECK: {{^}}test(#foobar){{$}} |
| 109 | */ |