Clang Project

clang_source_code/test/Preprocessor/pragma_diagnostic.c
1// RUN: %clang_cc1 -fsyntax-only -verify -Wno-undef %s
2// RUN: %clang_cc1 -fsyntax-only -verify -Wno-undef -Wno-unknown-warning-option -DAVOID_UNKNOWN_WARNING %s
3// rdar://2362963
4
5#if FOO    // ok.
6#endif
7
8#pragma GCC diagnostic warning "-Wundef"
9
10#if FOO    // expected-warning {{'FOO' is not defined}}
11#endif
12
13#pragma GCC diagnostic ignored "-Wun" "def"
14
15#if FOO    // ok.
16#endif
17
18#pragma GCC diagnostic error "-Wundef"
19
20#if FOO    // expected-error {{'FOO' is not defined}}
21#endif
22
23
24#define foo error
25#pragma GCC diagnostic foo "-Wundef"  // expected-warning {{pragma diagnostic expected 'error', 'warning', 'ignored', 'fatal', 'push', or 'pop'}}
26
27#pragma GCC diagnostic error 42  // expected-error {{expected string literal in pragma diagnostic}}
28
29#pragma GCC diagnostic error "-Wundef" 42  // expected-warning {{unexpected token in pragma diagnostic}}
30#pragma GCC diagnostic error "invalid-name"  // expected-warning {{pragma diagnostic expected option name (e.g. "-Wundef")}}
31
32#pragma GCC diagnostic error "-Winvalid-name"
33#ifndef AVOID_UNKNOWN_WARNING
34// expected-warning@-2 {{unknown warning group '-Winvalid-name', ignored}}
35#endif
36
37// Testing pragma clang diagnostic with -Weverything
38void ppo(){} // First test that we do not diagnose on this.
39
40#pragma clang diagnostic warning "-Weverything"
41void ppp(){} // expected-warning {{no previous prototype for function 'ppp'}}
42
43#pragma clang diagnostic ignored "-Weverything" // Reset it.
44void ppq(){}
45
46#pragma clang diagnostic error "-Weverything" // Now set to error
47void ppr(){} // expected-error {{no previous prototype for function 'ppr'}}
48
49#pragma clang diagnostic warning "-Weverything" // This should not be effective
50void pps(){} // expected-error {{no previous prototype for function 'pps'}}
51