1 /* Copyright (C) 2017-2023 Free Software Foundation, Inc.
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.
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.
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/>. */
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.
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.
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"). */
34 # define DIAGNOSTIC_PUSH _Pragma ("GCC diagnostic push")
35 # define DIAGNOSTIC_POP _Pragma ("GCC diagnostic pop")
37 /* Stringification. */
38 # define DIAGNOSTIC_STRINGIFY_1(x) #x
39 # define DIAGNOSTIC_STRINGIFY(x) DIAGNOSTIC_STRINGIFY_1 (x)
41 # define DIAGNOSTIC_IGNORE(option) \
42 _Pragma (DIAGNOSTIC_STRINGIFY (GCC diagnostic ignored option))
43 # define DIAGNOSTIC_ERROR(option) \
44 _Pragma (DIAGNOSTIC_STRINGIFY (GCC diagnostic error option))
46 # define DIAGNOSTIC_PUSH
47 # define DIAGNOSTIC_POP
48 # define DIAGNOSTIC_IGNORE(option)
51 #if defined (__clang__) /* clang */
53 # define DIAGNOSTIC_IGNORE_SELF_MOVE DIAGNOSTIC_IGNORE ("-Wself-move")
54 # define DIAGNOSTIC_IGNORE_DEPRECATED_DECLARATIONS \
55 DIAGNOSTIC_IGNORE ("-Wdeprecated-declarations")
56 # define DIAGNOSTIC_IGNORE_DEPRECATED_REGISTER \
57 DIAGNOSTIC_IGNORE ("-Wdeprecated-register")
58 # if __has_warning ("-Wenum-compare-switch")
59 # define DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES \
60 DIAGNOSTIC_IGNORE ("-Wenum-compare-switch")
63 # define DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL \
64 DIAGNOSTIC_IGNORE ("-Wformat-nonliteral")
66 # if __has_warning ("-Wuser-defined-warnings")
67 # define DIAGNOSTIC_IGNORE_USER_DEFINED_WARNINGS \
68 DIAGNOSTIC_IGNORE ("-Wuser-defined-warnings")
71 # if __has_warning ("-Wunused-but-set-variable")
72 # define DIAGNOSTIC_IGNORE_UNUSED_BUT_SET_VARIABLE \
73 DIAGNOSTIC_IGNORE ("-Wunused-but-set-variable")
76 # define DIAGNOSTIC_ERROR_SWITCH \
77 DIAGNOSTIC_ERROR ("-Wswitch")
79 # if __has_warning ("-Wenum-constexpr-conversion")
80 # define DIAGNOSTIC_IGNORE_ENUM_CONSTEXPR_CONVERSION \
81 DIAGNOSTIC_IGNORE ("-Wenum-constexpr-conversion")
84 #elif defined (__GNUC__) /* GCC */
86 # define DIAGNOSTIC_IGNORE_DEPRECATED_DECLARATIONS \
87 DIAGNOSTIC_IGNORE ("-Wdeprecated-declarations")
90 # define DIAGNOSTIC_IGNORE_DEPRECATED_REGISTER \
91 DIAGNOSTIC_IGNORE ("-Wregister")
94 # define DIAGNOSTIC_IGNORE_STRINGOP_TRUNCATION \
95 DIAGNOSTIC_IGNORE ("-Wstringop-truncation")
98 # define DIAGNOSTIC_IGNORE_STRINGOP_OVERREAD \
99 DIAGNOSTIC_IGNORE ("-Wstringop-overread")
102 # define DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL \
103 DIAGNOSTIC_IGNORE ("-Wformat-nonliteral")
106 # define DIAGNOSTIC_IGNORE_UNUSED_BUT_SET_VARIABLE \
107 DIAGNOSTIC_IGNORE ("-Wunused-but-set-variable")
111 # define DIAGNOSTIC_IGNORE_SELF_MOVE DIAGNOSTIC_IGNORE ("-Wself-move")
114 /* GCC 4.8's "diagnostic push/pop" seems broken when using this, -Wswitch
115 remains enabled at the error level even after a pop. Therefore, don't
116 use it for GCC < 5. */
118 # define DIAGNOSTIC_ERROR_SWITCH DIAGNOSTIC_ERROR ("-Wswitch")
123 #ifndef DIAGNOSTIC_IGNORE_SELF_MOVE
124 # define DIAGNOSTIC_IGNORE_SELF_MOVE
127 #ifndef DIAGNOSTIC_IGNORE_DEPRECATED_DECLARATIONS
128 # define DIAGNOSTIC_IGNORE_DEPRECATED_DECLARATIONS
131 #ifndef DIAGNOSTIC_IGNORE_DEPRECATED_REGISTER
132 # define DIAGNOSTIC_IGNORE_DEPRECATED_REGISTER
135 #ifndef DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
136 # define DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
139 #ifndef DIAGNOSTIC_IGNORE_STRINGOP_TRUNCATION
140 # define DIAGNOSTIC_IGNORE_STRINGOP_TRUNCATION
143 #ifndef DIAGNOSTIC_IGNORE_STRINGOP_OVERREAD
144 # define DIAGNOSTIC_IGNORE_STRINGOP_OVERREAD
147 #ifndef DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL
148 # define DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL
151 #ifndef DIAGNOSTIC_IGNORE_USER_DEFINED_WARNINGS
152 # define DIAGNOSTIC_IGNORE_USER_DEFINED_WARNINGS
155 #ifndef DIAGNOSTIC_IGNORE_UNUSED_BUT_SET_VARIABLE
156 # define DIAGNOSTIC_IGNORE_UNUSED_BUT_SET_VARIABLE
159 #ifndef DIAGNOSTIC_ERROR_SWITCH
160 # define DIAGNOSTIC_ERROR_SWITCH
163 #ifndef DIAGNOSTIC_IGNORE_ENUM_CONSTEXPR_CONVERSION
164 # define DIAGNOSTIC_IGNORE_ENUM_CONSTEXPR_CONVERSION
167 #endif /* DIAGNOSTICS_H */