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