pragma_diagnostic_sections.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // RUN: %clang_cc1 -fsyntax-only -Wall -Wunused-macros -Wunused-parameter -Wno-uninitialized -verify %s
  2. // rdar://8365684
  3. struct S {
  4. void m1() { int b; while (b==b); } // expected-warning {{always evaluates to true}}
  5. #pragma clang diagnostic push
  6. #pragma clang diagnostic ignored "-Wtautological-compare"
  7. void m2() { int b; while (b==b); }
  8. #pragma clang diagnostic pop
  9. void m3() { int b; while (b==b); } // expected-warning {{always evaluates to true}}
  10. };
  11. //------------------------------------------------------------------------------
  12. #pragma clang diagnostic push
  13. #pragma clang diagnostic ignored "-Wtautological-compare"
  14. template <typename T>
  15. struct TS {
  16. void m() { T b; while (b==b); }
  17. };
  18. #pragma clang diagnostic pop
  19. void f() {
  20. TS<int> ts;
  21. ts.m();
  22. }
  23. //------------------------------------------------------------------------------
  24. #define UNUSED_MACRO1 // expected-warning {{macro is not used}}
  25. #pragma clang diagnostic push
  26. #pragma clang diagnostic ignored "-Wunused-macros"
  27. #define UNUSED_MACRO2
  28. #pragma clang diagnostic pop
  29. //------------------------------------------------------------------------------
  30. #pragma clang diagnostic push
  31. #pragma clang diagnostic ignored "-Wreturn-type"
  32. int g() { }
  33. #pragma clang diagnostic pop
  34. //------------------------------------------------------------------------------
  35. void ww(
  36. #pragma clang diagnostic push
  37. #pragma clang diagnostic ignored "-Wunused-parameter"
  38. int x,
  39. #pragma clang diagnostic pop
  40. int y) // expected-warning {{unused}}
  41. {
  42. }
  43. //------------------------------------------------------------------------------
  44. struct S2 {
  45. int x, y;
  46. S2() :
  47. #pragma clang diagnostic push
  48. #pragma clang diagnostic ignored "-Wreorder"
  49. y(),
  50. x()
  51. #pragma clang diagnostic pop
  52. {}
  53. };
  54. //------------------------------------------------------------------------------
  55. // rdar://8790245
  56. #define MYMACRO \
  57. _Pragma("clang diagnostic push") \
  58. _Pragma("clang diagnostic ignored \"-Wunknown-pragmas\"") \
  59. _Pragma("clang diagnostic pop")
  60. MYMACRO
  61. #undef MYMACRO
  62. //------------------------------------------------------------------------------