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