warn-sysheader.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. // Test that -Wsystem-headers works with default and custom mappings like -Werror.
  2. // Keep run lines at the bottom for line number stability.
  3. #ifdef IS_SYSHEADER
  4. #pragma clang system_header
  5. int f() { return (int)0; } // Use the old-style-cast warning as an arbitrary "ordinary" diagnostic for the purpose of testing.
  6. #warning "custom message"
  7. #if defined(A) || defined(B)
  8. // expected-warning@9 {{"custom message"}}
  9. #elif defined(C)
  10. // expected-warning@7 {{use of old-style cast}}
  11. // expected-warning@9 {{"custom message"}}
  12. #elif defined(D)
  13. // expected-error@7 {{use of old-style cast}}
  14. // expected-error@9 {{"custom message"}}
  15. #elif defined(E)
  16. // expected-error@7 {{use of old-style cast}}
  17. // expected-warning@9 {{"custom message"}}
  18. #endif
  19. #else
  20. #define IS_SYSHEADER
  21. #include __FILE__
  22. #endif
  23. // RUN: %clang_cc1 -verify -fsyntax-only -DA %s
  24. // RUN: %clang_cc1 -verify -fsyntax-only -DB -Wold-style-cast %s
  25. // RUN: %clang_cc1 -verify -fsyntax-only -DC -Wold-style-cast -Wsystem-headers %s
  26. // RUN: %clang_cc1 -verify -fsyntax-only -DD -Wold-style-cast -Wsystem-headers -Werror %s
  27. // RUN: %clang_cc1 -verify -fsyntax-only -DE -Wold-style-cast -Wsystem-headers -Werror=old-style-cast %s