traditional-cpp.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. RUN: %clang_cc1 -traditional-cpp %s -E | FileCheck -strict-whitespace %s
  6. RUN: %clang_cc1 -traditional-cpp %s -E -C | FileCheck -check-prefix=CHECK-COMMENTS %s
  7. RUN: %clang_cc1 -traditional-cpp -x c++ %s -E | FileCheck -check-prefix=CHECK-CXX %s
  8. */
  9. /* -traditional-cpp should eliminate all C89 comments. */
  10. /* CHECK-NOT: /*
  11. * CHECK-COMMENTS: {{^}}/* -traditional-cpp should eliminate all C89 comments. *{{/$}}
  12. */
  13. /* -traditional-cpp should only eliminate "//" comments in C++ mode. */
  14. /* CHECK: {{^}}foo // bar{{$}}
  15. * CHECK-CXX: {{^}}foo {{$}}
  16. */
  17. foo // bar
  18. /* The lines in this file contain hard tab characters and trailing whitespace;
  19. * do not change them! */
  20. /* CHECK: {{^}} indented!{{$}}
  21. * CHECK: {{^}}tab separated values{{$}}
  22. */
  23. indented!
  24. tab separated values
  25. #define bracket(x) >>>x<<<
  26. bracket(| spaces |)
  27. /* CHECK: {{^}}>>>| spaces |<<<{{$}}
  28. */
  29. /* This is still a preprocessing directive. */
  30. # define foo bar
  31. foo!
  32. -
  33. foo! foo!
  34. /* CHECK: {{^}}bar!{{$}}
  35. * CHECK: {{^}} bar! bar! {{$}}
  36. */
  37. /* Deliberately check a leading newline with spaces on that line. */
  38. # define foo bar
  39. foo!
  40. -
  41. foo! foo!
  42. /* CHECK: {{^}}bar!{{$}}
  43. * CHECK: {{^}} bar! bar! {{$}}
  44. */
  45. /* FIXME: -traditional-cpp should not consider this a preprocessing directive
  46. * because the # isn't in the first column.
  47. */
  48. #define foo2 bar
  49. foo2!
  50. /* If this were working, both of these checks would be on.
  51. * CHECK-NOT: {{^}} #define foo2 bar{{$}}
  52. * CHECK-NOT: {{^}}foo2!{{$}}
  53. */
  54. /* FIXME: -traditional-cpp should not homogenize whitespace in macros.
  55. */
  56. #define bracket2(x) >>> x <<<
  57. bracket2(spaces)
  58. /* If this were working, this check would be on.
  59. * CHECK-NOT: {{^}}>>> spaces <<<{{$}}
  60. */
  61. /* Check that #if 0 blocks work as expected */
  62. #if 0
  63. #error "this is not an error"
  64. #if 1
  65. a b c in skipped block
  66. #endif
  67. /* Comments are whitespace too */
  68. #endif
  69. /* CHECK-NOT: {{^}}a b c in skipped block{{$}}
  70. * CHECK-NOT: {{^}}/* Comments are whitespace too
  71. */
  72. Preserve URLs: http://clang.llvm.org
  73. /* CHECK: {{^}}Preserve URLs: http://clang.llvm.org{{$}}
  74. */
  75. /* The following tests ensure we ignore # and ## in macro bodies */
  76. #define FOO_NO_STRINGIFY(a) test(# a)
  77. FOO_NO_STRINGIFY(foobar)
  78. /* CHECK: {{^}}test(# foobar){{$}}
  79. */
  80. #define FOO_NO_PASTE(a, b) test(b##a)
  81. FOO_NO_PASTE(foo,bar)
  82. /* CHECK {{^}}test(bar##foo){{$}}
  83. */
  84. #define BAR_NO_STRINGIFY(a) test(#a)
  85. BAR_NO_STRINGIFY(foobar)
  86. /* CHECK: {{^}}test(#foobar){{$}}
  87. */