1 /* Macros for controlling diagnostic output from the compiler.
2 Copyright (C) 2014-2017 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
20 #define _LIBC_DIAG_H 1
22 /* Ignore the value of an expression when a cast to void does not
23 suffice (in particular, for a call to a function declared with
24 attribute warn_unused_result). */
25 #define ignore_value(x) \
26 ({ __typeof__ (x) __ignored_value = (x); (void) __ignored_value; })
28 /* The macros to control diagnostics are structured like this, rather
29 than a single macro that both pushes and pops diagnostic state and
30 takes the affected code as an argument, because the GCC pragmas
31 work by disabling the diagnostic for a range of source locations
32 and do not work when all the pragmas and the affected code are in a
33 single macro expansion. */
35 /* Push diagnostic state. */
36 #define DIAG_PUSH_NEEDS_COMMENT _Pragma ("GCC diagnostic push")
38 /* Pop diagnostic state. */
39 #define DIAG_POP_NEEDS_COMMENT _Pragma ("GCC diagnostic pop")
41 #define _DIAG_STR1(s) #s
42 #define _DIAG_STR(s) _DIAG_STR1(s)
44 /* Ignore the diagnostic OPTION. VERSION is the most recent GCC
45 version for which the diagnostic has been confirmed to appear in
46 the absence of the pragma (in the form MAJOR.MINOR for GCC 4.x,
47 just MAJOR for GCC 5 and later). Uses of this pragma should be
48 reviewed when the GCC version given is no longer supported for
49 building glibc; the version number should always be on the same
50 source line as the macro name, so such uses can be found with grep.
51 Uses should come with a comment giving more details of the
52 diagnostic, and an architecture on which it is seen if possibly
53 optimization-related and not in architecture-specific code. This
54 macro should only be used if the diagnostic seems hard to fix (for
55 example, optimization-related false positives). */
56 #define DIAG_IGNORE_NEEDS_COMMENT(version, option) \
57 _Pragma (_DIAG_STR (GCC diagnostic ignored option))
59 /* Similar to DIAG_IGNORE_NEEDS_COMMENT the following macro ignores the
60 diagnostic OPTION but only if optimizations for size are enabled.
61 This is required because different warnings may be generated for
62 different optimization levels. For example a key piece of code may
63 only generate a warning when compiled at -Os, but at -O2 you could
64 still want the warning to be enabled to catch errors. In this case
65 you would use DIAG_IGNORE_Os_NEEDS_COMMENT to disable the warning
67 #ifdef __OPTIMIZE_SIZE__
68 # define DIAG_IGNORE_Os_NEEDS_COMMENT(version, option) \
69 _Pragma (_DIAG_STR (GCC diagnostic ignored option))
71 # define DIAG_IGNORE_Os_NEEDS_COMMENT(version, option)
74 #endif /* libc-diag.h */