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