]>
Commit | Line | Data |
---|---|---|
fd67aa11 | 1 | /* Copyright (C) 2017-2024 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)) |
6cade918 SM |
43 | # define DIAGNOSTIC_ERROR(option) \ |
44 | _Pragma (DIAGNOSTIC_STRINGIFY (GCC diagnostic error option)) | |
f4906a9a PA |
45 | #else |
46 | # define DIAGNOSTIC_PUSH | |
47 | # define DIAGNOSTIC_POP | |
48 | # define DIAGNOSTIC_IGNORE(option) | |
49 | #endif | |
50 | ||
8b5a7a6e SM |
51 | #if defined (__clang__) /* clang */ |
52 | ||
f4906a9a | 53 | # define DIAGNOSTIC_IGNORE_SELF_MOVE DIAGNOSTIC_IGNORE ("-Wself-move") |
6821842f SM |
54 | # define DIAGNOSTIC_IGNORE_DEPRECATED_DECLARATIONS \ |
55 | DIAGNOSTIC_IGNORE ("-Wdeprecated-declarations") | |
ecc3c386 SM |
56 | # define DIAGNOSTIC_IGNORE_REGISTER DIAGNOSTIC_IGNORE ("-Wregister") |
57 | ||
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 | ||
c59ea02c TO |
66 | # if __has_warning ("-Wuser-defined-warnings") |
67 | # define DIAGNOSTIC_IGNORE_USER_DEFINED_WARNINGS \ | |
68 | DIAGNOSTIC_IGNORE ("-Wuser-defined-warnings") | |
69 | # endif | |
70 | ||
d9fa9b7c TO |
71 | # if __has_warning ("-Wunused-but-set-variable") |
72 | # define DIAGNOSTIC_IGNORE_UNUSED_BUT_SET_VARIABLE \ | |
73 | DIAGNOSTIC_IGNORE ("-Wunused-but-set-variable") | |
74 | # endif | |
75 | ||
6cade918 SM |
76 | # define DIAGNOSTIC_ERROR_SWITCH \ |
77 | DIAGNOSTIC_ERROR ("-Wswitch") | |
78 | ||
ae61525f SM |
79 | # if __has_warning ("-Wenum-constexpr-conversion") |
80 | # define DIAGNOSTIC_IGNORE_ENUM_CONSTEXPR_CONVERSION \ | |
81 | DIAGNOSTIC_IGNORE ("-Wenum-constexpr-conversion") | |
82 | # endif | |
83 | ||
8b5a7a6e SM |
84 | #elif defined (__GNUC__) /* GCC */ |
85 | ||
56d4450b TO |
86 | # define DIAGNOSTIC_IGNORE_DEPRECATED_DECLARATIONS \ |
87 | DIAGNOSTIC_IGNORE ("-Wdeprecated-declarations") | |
88 | ||
b8fff44e | 89 | # if __GNUC__ >= 7 |
ecc3c386 | 90 | # define DIAGNOSTIC_IGNORE_REGISTER DIAGNOSTIC_IGNORE ("-Wregister") |
b8fff44e MW |
91 | # endif |
92 | ||
95da9854 | 93 | # define DIAGNOSTIC_IGNORE_STRINGOP_TRUNCATION \ |
23081219 | 94 | DIAGNOSTIC_IGNORE ("-Wstringop-truncation") |
af39b1c2 | 95 | |
f1e14eee | 96 | # if __GNUC__ >= 11 |
716e5473 MW |
97 | # define DIAGNOSTIC_IGNORE_STRINGOP_OVERREAD \ |
98 | DIAGNOSTIC_IGNORE ("-Wstringop-overread") | |
f1e14eee | 99 | #endif |
716e5473 | 100 | |
af39b1c2 SM |
101 | # define DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL \ |
102 | DIAGNOSTIC_IGNORE ("-Wformat-nonliteral") | |
103 | ||
d9fa9b7c TO |
104 | # if __GNUC__ >= 5 |
105 | # define DIAGNOSTIC_IGNORE_UNUSED_BUT_SET_VARIABLE \ | |
106 | DIAGNOSTIC_IGNORE ("-Wunused-but-set-variable") | |
107 | # endif | |
108 | ||
aef1974a JBG |
109 | # if __GNUC__ >= 13 |
110 | # define DIAGNOSTIC_IGNORE_SELF_MOVE DIAGNOSTIC_IGNORE ("-Wself-move") | |
111 | # endif | |
112 | ||
6cade918 SM |
113 | /* GCC 4.8's "diagnostic push/pop" seems broken when using this, -Wswitch |
114 | remains enabled at the error level even after a pop. Therefore, don't | |
115 | use it for GCC < 5. */ | |
116 | # if __GNUC__ >= 5 | |
117 | # define DIAGNOSTIC_ERROR_SWITCH DIAGNOSTIC_ERROR ("-Wswitch") | |
118 | # endif | |
119 | ||
23081219 | 120 | #endif |
8b5a7a6e | 121 | |
23081219 | 122 | #ifndef DIAGNOSTIC_IGNORE_SELF_MOVE |
f4906a9a | 123 | # define DIAGNOSTIC_IGNORE_SELF_MOVE |
23081219 L |
124 | #endif |
125 | ||
6821842f SM |
126 | #ifndef DIAGNOSTIC_IGNORE_DEPRECATED_DECLARATIONS |
127 | # define DIAGNOSTIC_IGNORE_DEPRECATED_DECLARATIONS | |
128 | #endif | |
129 | ||
ecc3c386 SM |
130 | #ifndef DIAGNOSTIC_IGNORE_REGISTER |
131 | # define DIAGNOSTIC_IGNORE_REGISTER | |
23081219 L |
132 | #endif |
133 | ||
23081219 | 134 | #ifndef DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES |
0436426c | 135 | # define DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES |
23081219 | 136 | #endif |
0436426c | 137 | |
23081219 L |
138 | #ifndef DIAGNOSTIC_IGNORE_STRINGOP_TRUNCATION |
139 | # define DIAGNOSTIC_IGNORE_STRINGOP_TRUNCATION | |
f4906a9a PA |
140 | #endif |
141 | ||
716e5473 MW |
142 | #ifndef DIAGNOSTIC_IGNORE_STRINGOP_OVERREAD |
143 | # define DIAGNOSTIC_IGNORE_STRINGOP_OVERREAD | |
144 | #endif | |
145 | ||
af39b1c2 SM |
146 | #ifndef DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL |
147 | # define DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL | |
148 | #endif | |
149 | ||
c59ea02c TO |
150 | #ifndef DIAGNOSTIC_IGNORE_USER_DEFINED_WARNINGS |
151 | # define DIAGNOSTIC_IGNORE_USER_DEFINED_WARNINGS | |
152 | #endif | |
153 | ||
d9fa9b7c TO |
154 | #ifndef DIAGNOSTIC_IGNORE_UNUSED_BUT_SET_VARIABLE |
155 | # define DIAGNOSTIC_IGNORE_UNUSED_BUT_SET_VARIABLE | |
156 | #endif | |
157 | ||
6cade918 SM |
158 | #ifndef DIAGNOSTIC_ERROR_SWITCH |
159 | # define DIAGNOSTIC_ERROR_SWITCH | |
160 | #endif | |
161 | ||
ae61525f SM |
162 | #ifndef DIAGNOSTIC_IGNORE_ENUM_CONSTEXPR_CONVERSION |
163 | # define DIAGNOSTIC_IGNORE_ENUM_CONSTEXPR_CONVERSION | |
164 | #endif | |
165 | ||
e9cb46ab | 166 | #endif /* DIAGNOSTICS_H */ |