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 * SPDX-License-Identifier: GPL-2.0+
13 #ifndef __WS_DIAG_CONTROL_H__
14 #define __WS_DIAG_CONTROL_H__
16 #include "ws_compiler_tests.h"
22 #define XSTRINGIFY(x) #x
25 * Macros for controlling warnings in GCC >= 4.2 and clang >= 2.8
27 #define DIAG_JOINSTR(x,y) XSTRINGIFY(x ## y)
28 #define DIAG_DO_PRAGMA(x) _Pragma (#x)
30 #if defined(__clang__)
32 * Clang, so we'd use _Pragma("clang diagnostic XXX"), if it's
35 #if WS_IS_AT_LEAST_CLANG_VERSION(2,8)
37 * This is Clang 2.8 or later: we can use "clang diagnostic ignored -Wxxx"
38 * and "clang diagnostic push/pop".
40 #define DIAG_PRAGMA(x) DIAG_DO_PRAGMA(clang diagnostic x)
41 #define DIAG_OFF(x) DIAG_PRAGMA(push) DIAG_PRAGMA(ignored DIAG_JOINSTR(-W,x))
42 #define DIAG_ON(x) DIAG_PRAGMA(pop)
44 #elif defined(__GNUC__)
46 * GCC, or a compiler (other than Clang) that claims to be GCC.
47 * We assume that the compiler accepts _Pragma("GCC diagnostic xxx")
48 * even if it's only claiming to be GCC.
50 #if WS_IS_AT_LEAST_GNUC_VERSION(4,8)
52 * This is GCC 4.8 or later, or a compiler claiming to be that.
53 * We can use "GCC diagnostic ignored -Wxxx" (introduced in 4.2)
54 * and "GCC diagnostic push/pop" (introduced in 4.6), *and* gcc
55 * supports "-Wpedantic" (introduced in 4.8), allowing us to
56 * turn off pedantic warnings with DIAG_OFF().
58 #define DIAG_PRAGMA(x) DIAG_DO_PRAGMA(GCC diagnostic x)
59 #define DIAG_OFF(x) DIAG_PRAGMA(push) DIAG_PRAGMA(ignored DIAG_JOINSTR(-W,x))
60 #define DIAG_ON(x) DIAG_PRAGMA(pop)
66 * This is none of the above; we don't have any way to turn diagnostics
69 * XXX - you can do that in MSVC, but it's done differently; we'd
70 * have to have macros for *particular* diagnostics, using the
71 * warning flag for GCC and Clang and the error number for MSVC.
77 /* Use for clang specific pragmas, so we can keep -Wpragmas enabled */
79 # define DIAG_OFF_CLANG(x) DIAG_OFF(x)
80 # define DIAG_ON_CLANG(x) DIAG_ON(x)
82 # define DIAG_OFF_CLANG(x)
83 # define DIAG_ON_CLANG(x)
87 * For dealing with APIs which are only deprecated in macOS (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 macOS unless there's
92 * a sufficiently clear benefit to make it worth our while to have
93 * both macOS and non-macOS 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__ */