2 * Turn compiler diagnostic messages on and off.
4 * From FreeRADIUS build.h.
6 * @copyright 2013 The FreeRADIUS server project
8 * That project is covered by the GPLv2, so:
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #ifndef __WS_DIAG_CONTROL_H__
25 #define __WS_DIAG_CONTROL_H__
31 #define XSTRINGIFY(x) #x
34 * Macros for controlling warnings in GCC >= 4.2 and clang >= 2.8
36 #define DIAG_JOINSTR(x,y) XSTRINGIFY(x ## y)
37 #define DIAG_DO_PRAGMA(x) _Pragma (#x)
39 /* check the gcc or clang version
41 pragma GCC diagnostic error/warning/ignored -Wxxx was introduced
43 pragma GCC diagnostic push/pop was introduced in gcc 4.6.0
45 pragma clang diagnostic error/warning/ignored -Wxxx and
46 pragma clang diagnostic push/pop were introduced in clang 2.8 */
48 #if defined(__GNUC__) && !defined(__clang__)
49 # define gcc_version ((__GNUC__ * 1000) + (__GNUC_MINOR__ * 10))
50 # if gcc_version >= 4080
52 * gcc version is >= 4.8.0. We can use "GCC diagnostic push/pop" *and*
53 * gcc supports "-Wpedantic".
55 # define DIAG_PRAGMA(x) DIAG_DO_PRAGMA(GCC diagnostic x)
56 # define DIAG_OFF(x) DIAG_PRAGMA(push) DIAG_PRAGMA(ignored DIAG_JOINSTR(-W,x))
57 # define DIAG_ON(x) DIAG_PRAGMA(pop)
59 #elif defined(__clang__)
60 # define clang_version ((__clang_major__ * 1000) + (__clang_minor__ * 10))
61 # if clang_version >= 2080
62 /* clang version is >= 2.8: we can use "clang diagnostic ignored -Wxxx"
63 and "clang diagnostic push/pop" */
64 # define DIAG_PRAGMA(x) DIAG_DO_PRAGMA(clang diagnostic x)
65 # define DIAG_OFF(x) DIAG_PRAGMA(push) DIAG_PRAGMA(ignored DIAG_JOINSTR(-W,x))
66 # define DIAG_ON(x) DIAG_PRAGMA(pop)
70 /* Use for clang specific pragmas, so we can keep -Wpragmas enabled */
72 # define DIAG_OFF_CLANG(x) DIAG_OFF(x)
73 # define DIAG_ON_CLANG(x) DIAG_ON(x)
75 # define DIAG_OFF_CLANG(x)
76 # define DIAG_ON_CLANG(x)
80 /* no gcc or clang, or gcc version < 4.2.0, or clang version < 2.8:
81 we can't do anything */
87 * For dealing with APIs which are only deprecated in OS X (like the
88 * OpenSSL and MIT/Heimdal Kerberos APIs).
90 * Dear Apple: this is a cross-platform program, and we're not
91 * going to use your Shiny New Frameworks on OS X unless there's
92 * a sufficiently clear benefit to make it worth our while to have
93 * both OS X and non-OS X versions of the code.
96 # define USES_APPLE_DEPRECATED_API DIAG_OFF(deprecated-declarations)
97 # define USES_APPLE_RST DIAG_ON(deprecated-declarations)
99 # define USES_APPLE_DEPRECATED_API
100 # define USES_APPLE_RST
106 #endif /* __WS_DIAG_CONTROL_H__ */