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