Home | History | Annotate | Line # | Download | only in include
      1  1.1.1.5  christos /* Copyright (C) 2017-2025 Free Software Foundation, Inc.
      2      1.1  christos 
      3      1.1  christos    This program is free software; you can redistribute it and/or modify
      4      1.1  christos    it under the terms of the GNU General Public License as published by
      5      1.1  christos    the Free Software Foundation; either version 3 of the License, or
      6      1.1  christos    (at your option) any later version.
      7      1.1  christos 
      8      1.1  christos    This program is distributed in the hope that it will be useful,
      9      1.1  christos    but WITHOUT ANY WARRANTY; without even the implied warranty of
     10      1.1  christos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     11      1.1  christos    GNU General Public License for more details.
     12      1.1  christos 
     13      1.1  christos    You should have received a copy of the GNU General Public License
     14      1.1  christos    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
     15      1.1  christos 
     16      1.1  christos #ifndef DIAGNOSTICS_H
     17      1.1  christos #define DIAGNOSTICS_H
     18      1.1  christos 
     19      1.1  christos /* If at all possible, fix the source rather than using these macros
     20      1.1  christos    to silence warnings.  If you do use these macros be aware that
     21      1.1  christos    you'll need to condition their use on particular compiler versions,
     22      1.1  christos    which can be done for gcc using ansidecl.h's GCC_VERSION macro.
     23      1.1  christos 
     24      1.1  christos    gcc versions between 4.2 and 4.6 do not allow pragma control of
     25      1.1  christos    diagnostics inside functions, giving a hard error if you try to use
     26      1.1  christos    the finer control available with later versions.
     27      1.1  christos    gcc prior to 4.2 warns about diagnostic push and pop.
     28      1.1  christos 
     29      1.1  christos    The other macros have restrictions too, for example gcc-5, gcc-6
     30      1.1  christos    and gcc-7 warn that -Wstringop-truncation is unknown, unless you
     31      1.1  christos    also add DIAGNOSTIC_IGNORE ("-Wpragma").  */
     32      1.1  christos 
     33      1.1  christos #ifdef __GNUC__
     34      1.1  christos # define DIAGNOSTIC_PUSH _Pragma ("GCC diagnostic push")
     35      1.1  christos # define DIAGNOSTIC_POP _Pragma ("GCC diagnostic pop")
     36      1.1  christos 
     37      1.1  christos /* Stringification.  */
     38      1.1  christos # define DIAGNOSTIC_STRINGIFY_1(x) #x
     39      1.1  christos # define DIAGNOSTIC_STRINGIFY(x) DIAGNOSTIC_STRINGIFY_1 (x)
     40      1.1  christos 
     41      1.1  christos # define DIAGNOSTIC_IGNORE(option) \
     42      1.1  christos   _Pragma (DIAGNOSTIC_STRINGIFY (GCC diagnostic ignored option))
     43  1.1.1.3  christos # define DIAGNOSTIC_ERROR(option) \
     44  1.1.1.3  christos   _Pragma (DIAGNOSTIC_STRINGIFY (GCC diagnostic error option))
     45      1.1  christos #else
     46      1.1  christos # define DIAGNOSTIC_PUSH
     47      1.1  christos # define DIAGNOSTIC_POP
     48      1.1  christos # define DIAGNOSTIC_IGNORE(option)
     49      1.1  christos #endif
     50      1.1  christos 
     51      1.1  christos #if defined (__clang__) /* clang */
     52      1.1  christos 
     53      1.1  christos # define DIAGNOSTIC_IGNORE_SELF_MOVE DIAGNOSTIC_IGNORE ("-Wself-move")
     54  1.1.1.2  christos # define DIAGNOSTIC_IGNORE_DEPRECATED_DECLARATIONS \
     55  1.1.1.2  christos   DIAGNOSTIC_IGNORE ("-Wdeprecated-declarations")
     56  1.1.1.5  christos # define DIAGNOSTIC_IGNORE_REGISTER DIAGNOSTIC_IGNORE ("-Wregister")
     57  1.1.1.5  christos 
     58      1.1  christos # if __has_warning ("-Wenum-compare-switch")
     59      1.1  christos #  define DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES \
     60      1.1  christos    DIAGNOSTIC_IGNORE ("-Wenum-compare-switch")
     61      1.1  christos # endif
     62      1.1  christos 
     63  1.1.1.2  christos # define DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL \
     64  1.1.1.2  christos   DIAGNOSTIC_IGNORE ("-Wformat-nonliteral")
     65  1.1.1.2  christos 
     66  1.1.1.4  christos # if __has_warning ("-Wuser-defined-warnings")
     67  1.1.1.4  christos #  define DIAGNOSTIC_IGNORE_USER_DEFINED_WARNINGS \
     68  1.1.1.4  christos    DIAGNOSTIC_IGNORE ("-Wuser-defined-warnings")
     69  1.1.1.4  christos # endif
     70  1.1.1.4  christos 
     71  1.1.1.4  christos # if __has_warning ("-Wunused-but-set-variable")
     72  1.1.1.4  christos #  define DIAGNOSTIC_IGNORE_UNUSED_BUT_SET_VARIABLE \
     73  1.1.1.4  christos    DIAGNOSTIC_IGNORE ("-Wunused-but-set-variable")
     74  1.1.1.4  christos # endif
     75  1.1.1.4  christos 
     76  1.1.1.3  christos # define DIAGNOSTIC_ERROR_SWITCH \
     77  1.1.1.3  christos   DIAGNOSTIC_ERROR ("-Wswitch")
     78  1.1.1.3  christos 
     79  1.1.1.2  christos #elif defined (__GNUC__) /* GCC */
     80      1.1  christos 
     81  1.1.1.4  christos # define DIAGNOSTIC_IGNORE_DEPRECATED_DECLARATIONS \
     82  1.1.1.4  christos   DIAGNOSTIC_IGNORE ("-Wdeprecated-declarations")
     83  1.1.1.4  christos 
     84  1.1.1.3  christos # if __GNUC__ >= 7
     85  1.1.1.5  christos #  define DIAGNOSTIC_IGNORE_REGISTER DIAGNOSTIC_IGNORE ("-Wregister")
     86  1.1.1.3  christos # endif
     87  1.1.1.3  christos 
     88      1.1  christos # define DIAGNOSTIC_IGNORE_STRINGOP_TRUNCATION \
     89      1.1  christos   DIAGNOSTIC_IGNORE ("-Wstringop-truncation")
     90  1.1.1.2  christos 
     91  1.1.1.3  christos # if __GNUC__ >= 11
     92  1.1.1.3  christos # define DIAGNOSTIC_IGNORE_STRINGOP_OVERREAD \
     93  1.1.1.3  christos   DIAGNOSTIC_IGNORE ("-Wstringop-overread")
     94  1.1.1.3  christos #endif
     95  1.1.1.3  christos 
     96  1.1.1.2  christos # define DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL \
     97  1.1.1.2  christos   DIAGNOSTIC_IGNORE ("-Wformat-nonliteral")
     98  1.1.1.2  christos 
     99  1.1.1.4  christos # if __GNUC__ >= 5
    100  1.1.1.4  christos #  define DIAGNOSTIC_IGNORE_UNUSED_BUT_SET_VARIABLE \
    101  1.1.1.4  christos    DIAGNOSTIC_IGNORE ("-Wunused-but-set-variable")
    102  1.1.1.4  christos # endif
    103  1.1.1.4  christos 
    104  1.1.1.4  christos # if __GNUC__ >= 13
    105  1.1.1.4  christos #  define DIAGNOSTIC_IGNORE_SELF_MOVE DIAGNOSTIC_IGNORE ("-Wself-move")
    106  1.1.1.4  christos # endif
    107  1.1.1.4  christos 
    108  1.1.1.3  christos /* GCC 4.8's "diagnostic push/pop" seems broken when using this, -Wswitch
    109  1.1.1.3  christos    remains enabled at the error level even after a pop.  Therefore, don't
    110  1.1.1.3  christos    use it for GCC < 5.  */
    111  1.1.1.3  christos # if __GNUC__ >= 5
    112  1.1.1.3  christos #  define DIAGNOSTIC_ERROR_SWITCH DIAGNOSTIC_ERROR ("-Wswitch")
    113  1.1.1.3  christos # endif
    114  1.1.1.3  christos 
    115      1.1  christos #endif
    116      1.1  christos 
    117      1.1  christos #ifndef DIAGNOSTIC_IGNORE_SELF_MOVE
    118      1.1  christos # define DIAGNOSTIC_IGNORE_SELF_MOVE
    119      1.1  christos #endif
    120      1.1  christos 
    121  1.1.1.2  christos #ifndef DIAGNOSTIC_IGNORE_DEPRECATED_DECLARATIONS
    122  1.1.1.2  christos # define DIAGNOSTIC_IGNORE_DEPRECATED_DECLARATIONS
    123      1.1  christos #endif
    124      1.1  christos 
    125  1.1.1.5  christos #ifndef DIAGNOSTIC_IGNORE_REGISTER
    126  1.1.1.5  christos # define DIAGNOSTIC_IGNORE_REGISTER
    127      1.1  christos #endif
    128      1.1  christos 
    129      1.1  christos #ifndef DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
    130      1.1  christos # define DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
    131      1.1  christos #endif
    132      1.1  christos 
    133      1.1  christos #ifndef DIAGNOSTIC_IGNORE_STRINGOP_TRUNCATION
    134      1.1  christos # define DIAGNOSTIC_IGNORE_STRINGOP_TRUNCATION
    135      1.1  christos #endif
    136      1.1  christos 
    137  1.1.1.3  christos #ifndef DIAGNOSTIC_IGNORE_STRINGOP_OVERREAD
    138  1.1.1.3  christos # define DIAGNOSTIC_IGNORE_STRINGOP_OVERREAD
    139  1.1.1.3  christos #endif
    140  1.1.1.3  christos 
    141  1.1.1.2  christos #ifndef DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL
    142  1.1.1.2  christos # define DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL
    143  1.1.1.2  christos #endif
    144  1.1.1.2  christos 
    145  1.1.1.4  christos #ifndef DIAGNOSTIC_IGNORE_USER_DEFINED_WARNINGS
    146  1.1.1.4  christos # define DIAGNOSTIC_IGNORE_USER_DEFINED_WARNINGS
    147  1.1.1.4  christos #endif
    148  1.1.1.4  christos 
    149  1.1.1.4  christos #ifndef DIAGNOSTIC_IGNORE_UNUSED_BUT_SET_VARIABLE
    150  1.1.1.4  christos # define DIAGNOSTIC_IGNORE_UNUSED_BUT_SET_VARIABLE
    151  1.1.1.4  christos #endif
    152  1.1.1.4  christos 
    153  1.1.1.3  christos #ifndef DIAGNOSTIC_ERROR_SWITCH
    154  1.1.1.3  christos # define DIAGNOSTIC_ERROR_SWITCH
    155  1.1.1.3  christos #endif
    156  1.1.1.3  christos 
    157      1.1  christos #endif /* DIAGNOSTICS_H */
    158