Commit | Line | Data |
---|---|---|
82704155 | 1 | /* Copyright (C) 2017-2019 Free Software Foundation, Inc. |
f4906a9a | 2 | |
f4906a9a PA |
3 | This program is free software; you can redistribute it and/or modify |
4 | it under the terms of the GNU General Public License as published by | |
5 | the Free Software Foundation; either version 3 of the License, or | |
6 | (at your option) any later version. | |
7 | ||
8 | This program is distributed in the hope that it will be useful, | |
9 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 | GNU General Public License for more details. | |
12 | ||
13 | You should have received a copy of the GNU General Public License | |
14 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
15 | ||
e9cb46ab L |
16 | #ifndef DIAGNOSTICS_H |
17 | #define DIAGNOSTICS_H | |
f4906a9a | 18 | |
fe75810f AM |
19 | /* If at all possible, fix the source rather than using these macros |
20 | to silence warnings. If you do use these macros be aware that | |
21 | you'll need to condition their use on particular compiler versions, | |
22 | which can be done for gcc using ansidecl.h's GCC_VERSION macro. | |
23 | ||
24 | gcc versions between 4.2 and 4.6 do not allow pragma control of | |
25 | diagnostics inside functions, giving a hard error if you try to use | |
26 | the finer control available with later versions. | |
27 | gcc prior to 4.2 warns about diagnostic push and pop. | |
28 | ||
29 | The other macros have restrictions too, for example gcc-5, gcc-6 | |
30 | and gcc-7 warn that -Wstringop-truncation is unknown, unless you | |
31 | also add DIAGNOSTIC_IGNORE ("-Wpragma"). */ | |
32 | ||
f4906a9a PA |
33 | #ifdef __GNUC__ |
34 | # define DIAGNOSTIC_PUSH _Pragma ("GCC diagnostic push") | |
35 | # define DIAGNOSTIC_POP _Pragma ("GCC diagnostic pop") | |
23081219 L |
36 | |
37 | /* Stringification. */ | |
38 | # define DIAGNOSTIC_STRINGIFY_1(x) #x | |
39 | # define DIAGNOSTIC_STRINGIFY(x) DIAGNOSTIC_STRINGIFY_1 (x) | |
40 | ||
f4906a9a | 41 | # define DIAGNOSTIC_IGNORE(option) \ |
23081219 | 42 | _Pragma (DIAGNOSTIC_STRINGIFY (GCC diagnostic ignored option)) |
f4906a9a PA |
43 | #else |
44 | # define DIAGNOSTIC_PUSH | |
45 | # define DIAGNOSTIC_POP | |
46 | # define DIAGNOSTIC_IGNORE(option) | |
47 | #endif | |
48 | ||
8b5a7a6e SM |
49 | #if defined (__clang__) /* clang */ |
50 | ||
f4906a9a | 51 | # define DIAGNOSTIC_IGNORE_SELF_MOVE DIAGNOSTIC_IGNORE ("-Wself-move") |
6821842f SM |
52 | # define DIAGNOSTIC_IGNORE_DEPRECATED_DECLARATIONS \ |
53 | DIAGNOSTIC_IGNORE ("-Wdeprecated-declarations") | |
d1435379 SM |
54 | # define DIAGNOSTIC_IGNORE_DEPRECATED_REGISTER \ |
55 | DIAGNOSTIC_IGNORE ("-Wdeprecated-register") | |
8b5a7a6e SM |
56 | # define DIAGNOSTIC_IGNORE_UNUSED_FUNCTION \ |
57 | DIAGNOSTIC_IGNORE ("-Wunused-function") | |
cfa27c39 SM |
58 | # if __has_warning ("-Wenum-compare-switch") |
59 | # define DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES \ | |
60 | DIAGNOSTIC_IGNORE ("-Wenum-compare-switch") | |
cfa27c39 | 61 | # endif |
af39b1c2 SM |
62 | |
63 | # define DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL \ | |
64 | DIAGNOSTIC_IGNORE ("-Wformat-nonliteral") | |
65 | ||
8b5a7a6e SM |
66 | #elif defined (__GNUC__) /* GCC */ |
67 | ||
8b5a7a6e SM |
68 | # define DIAGNOSTIC_IGNORE_UNUSED_FUNCTION \ |
69 | DIAGNOSTIC_IGNORE ("-Wunused-function") | |
70 | ||
95da9854 | 71 | # define DIAGNOSTIC_IGNORE_STRINGOP_TRUNCATION \ |
23081219 | 72 | DIAGNOSTIC_IGNORE ("-Wstringop-truncation") |
af39b1c2 SM |
73 | |
74 | # define DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL \ | |
75 | DIAGNOSTIC_IGNORE ("-Wformat-nonliteral") | |
76 | ||
23081219 | 77 | #endif |
8b5a7a6e | 78 | |
23081219 | 79 | #ifndef DIAGNOSTIC_IGNORE_SELF_MOVE |
f4906a9a | 80 | # define DIAGNOSTIC_IGNORE_SELF_MOVE |
23081219 L |
81 | #endif |
82 | ||
6821842f SM |
83 | #ifndef DIAGNOSTIC_IGNORE_DEPRECATED_DECLARATIONS |
84 | # define DIAGNOSTIC_IGNORE_DEPRECATED_DECLARATIONS | |
85 | #endif | |
86 | ||
23081219 | 87 | #ifndef DIAGNOSTIC_IGNORE_DEPRECATED_REGISTER |
d1435379 | 88 | # define DIAGNOSTIC_IGNORE_DEPRECATED_REGISTER |
23081219 L |
89 | #endif |
90 | ||
91 | #ifndef DIAGNOSTIC_IGNORE_UNUSED_FUNCTION | |
8b5a7a6e | 92 | # define DIAGNOSTIC_IGNORE_UNUSED_FUNCTION |
23081219 L |
93 | #endif |
94 | ||
95 | #ifndef DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES | |
0436426c | 96 | # define DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES |
23081219 | 97 | #endif |
0436426c | 98 | |
23081219 L |
99 | #ifndef DIAGNOSTIC_IGNORE_STRINGOP_TRUNCATION |
100 | # define DIAGNOSTIC_IGNORE_STRINGOP_TRUNCATION | |
f4906a9a PA |
101 | #endif |
102 | ||
af39b1c2 SM |
103 | #ifndef DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL |
104 | # define DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL | |
105 | #endif | |
106 | ||
e9cb46ab | 107 | #endif /* DIAGNOSTICS_H */ |