Ted Kremenek | 183a8de | 2011-10-12 20:06:09 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only %s -verify |
| 2 | #ifndef __has_warning |
| 3 | #error Should have __has_warning |
| 4 | #endif |
| 5 | |
| 6 | #if __has_warning("not valid") // expected-warning {{__has_warning expected option name}} |
| 7 | #endif |
| 8 | |
Jordan Rose | 78541c4 | 2012-07-11 19:58:23 +0000 | [diff] [blame] | 9 | // expected-warning@+2 {{Should have -Wparentheses}} |
Ted Kremenek | 183a8de | 2011-10-12 20:06:09 +0000 | [diff] [blame] | 10 | #if __has_warning("-Wparentheses") |
Jordan Rose | 78541c4 | 2012-07-11 19:58:23 +0000 | [diff] [blame] | 11 | #warning Should have -Wparentheses |
Ted Kremenek | 183a8de | 2011-10-12 20:06:09 +0000 | [diff] [blame] | 12 | #endif |
| 13 | |
Andy Gibbs | 02a1768 | 2012-11-17 19:15:38 +0000 | [diff] [blame^] | 14 | // expected-error@+2 {{expected string literal}} |
Andy Gibbs | b9971ba | 2012-11-17 19:14:53 +0000 | [diff] [blame] | 15 | // expected-error@+1 {{expected value in expression}} |
| 16 | #if __has_warning(-Wfoo) |
Ted Kremenek | 183a8de | 2011-10-12 20:06:09 +0000 | [diff] [blame] | 17 | #endif |
| 18 | |
Jordan Rose | 78541c4 | 2012-07-11 19:58:23 +0000 | [diff] [blame] | 19 | // expected-warning@+3 {{Not a valid warning flag}} |
Ted Kremenek | 183a8de | 2011-10-12 20:06:09 +0000 | [diff] [blame] | 20 | #if __has_warning("-Wnot-a-valid-warning-flag-at-all") |
| 21 | #else |
Jordan Rose | 78541c4 | 2012-07-11 19:58:23 +0000 | [diff] [blame] | 22 | #warning Not a valid warning flag |
| 23 | #endif |
Andy Gibbs | 02a1768 | 2012-11-17 19:15:38 +0000 | [diff] [blame^] | 24 | |
| 25 | // expected-error@+2 {{builtin warning check macro requires a parenthesized string}} |
| 26 | // expected-error@+1 {{invalid token}} |
| 27 | #if __has_warning "not valid" |
| 28 | #endif |
| 29 | |
| 30 | // Macro expansion does not occur in the parameter to __has_warning |
| 31 | // (as is also expected behaviour for ordinary macros), so the |
| 32 | // following should not expand: |
| 33 | |
| 34 | #define MY_ALIAS "-Wparentheses" |
| 35 | |
| 36 | // expected-error@+1 2{{expected}} |
| 37 | #if __has_warning(MY_ALIAS) |
| 38 | #error Alias expansion not allowed |
| 39 | #endif |
| 40 | |
| 41 | // But deferring should expand: |
| 42 | #define HAS_WARNING(X) __has_warning(X) |
| 43 | |
| 44 | #if !HAS_WARNING(MY_ALIAS) |
| 45 | #error Expansion should have occurred |
| 46 | #endif |