warning_tests.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // RUN: %clang_cc1 -fsyntax-only %s -verify
  2. #ifndef __has_warning
  3. #error Should have __has_warning
  4. #endif
  5. #if __has_warning("not valid") // expected-warning {{__has_warning expected option name}}
  6. #endif
  7. // expected-warning@+2 {{Should have -Wparentheses}}
  8. #if __has_warning("-Wparentheses")
  9. #warning Should have -Wparentheses
  10. #endif
  11. // expected-error@+2 {{expected string literal in '__has_warning'}}
  12. // expected-error@+1 {{expected value in expression}}
  13. #if __has_warning(-Wfoo)
  14. #endif
  15. // expected-warning@+3 {{Not a valid warning flag}}
  16. #if __has_warning("-Wnot-a-valid-warning-flag-at-all")
  17. #else
  18. #warning Not a valid warning flag
  19. #endif
  20. // expected-error@+2 {{builtin warning check macro requires a parenthesized string}}
  21. // expected-error@+1 {{invalid token}}
  22. #if __has_warning "not valid"
  23. #endif
  24. // Macro expansion does not occur in the parameter to __has_warning
  25. // (as is also expected behaviour for ordinary macros), so the
  26. // following should not expand:
  27. #define MY_ALIAS "-Wparentheses"
  28. // expected-error@+1 2{{expected}}
  29. #if __has_warning(MY_ALIAS)
  30. #error Alias expansion not allowed
  31. #endif
  32. // But deferring should expand:
  33. #define HAS_WARNING(X) __has_warning(X)
  34. #if !HAS_WARNING(MY_ALIAS)
  35. #error Expansion should have occurred
  36. #endif