Home | History | Annotate | Line # | Download | only in include
diagnostics.h revision 1.1
      1  1.1  christos /* Copyright (C) 2017-2018 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  christos #else
     44  1.1  christos # define DIAGNOSTIC_PUSH
     45  1.1  christos # define DIAGNOSTIC_POP
     46  1.1  christos # define DIAGNOSTIC_IGNORE(option)
     47  1.1  christos #endif
     48  1.1  christos 
     49  1.1  christos #if defined (__clang__) /* clang */
     50  1.1  christos 
     51  1.1  christos # define DIAGNOSTIC_IGNORE_SELF_MOVE DIAGNOSTIC_IGNORE ("-Wself-move")
     52  1.1  christos # define DIAGNOSTIC_IGNORE_DEPRECATED_REGISTER \
     53  1.1  christos   DIAGNOSTIC_IGNORE ("-Wdeprecated-register")
     54  1.1  christos # define DIAGNOSTIC_IGNORE_UNUSED_FUNCTION \
     55  1.1  christos   DIAGNOSTIC_IGNORE ("-Wunused-function")
     56  1.1  christos # if __has_warning ("-Wenum-compare-switch")
     57  1.1  christos #  define DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES \
     58  1.1  christos    DIAGNOSTIC_IGNORE ("-Wenum-compare-switch")
     59  1.1  christos # endif
     60  1.1  christos #elif defined (__GNUC__) /* GCC */
     61  1.1  christos 
     62  1.1  christos # define DIAGNOSTIC_IGNORE_UNUSED_FUNCTION \
     63  1.1  christos   DIAGNOSTIC_IGNORE ("-Wunused-function")
     64  1.1  christos 
     65  1.1  christos # define DIAGNOSTIC_IGNORE_STRINGOP_TRUNCATION \
     66  1.1  christos   DIAGNOSTIC_IGNORE ("-Wstringop-truncation")
     67  1.1  christos #endif
     68  1.1  christos 
     69  1.1  christos #ifndef DIAGNOSTIC_IGNORE_SELF_MOVE
     70  1.1  christos # define DIAGNOSTIC_IGNORE_SELF_MOVE
     71  1.1  christos #endif
     72  1.1  christos 
     73  1.1  christos #ifndef DIAGNOSTIC_IGNORE_DEPRECATED_REGISTER
     74  1.1  christos # define DIAGNOSTIC_IGNORE_DEPRECATED_REGISTER
     75  1.1  christos #endif
     76  1.1  christos 
     77  1.1  christos #ifndef DIAGNOSTIC_IGNORE_UNUSED_FUNCTION
     78  1.1  christos # define DIAGNOSTIC_IGNORE_UNUSED_FUNCTION
     79  1.1  christos #endif
     80  1.1  christos 
     81  1.1  christos #ifndef DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
     82  1.1  christos # define DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
     83  1.1  christos #endif
     84  1.1  christos 
     85  1.1  christos #ifndef DIAGNOSTIC_IGNORE_STRINGOP_TRUNCATION
     86  1.1  christos # define DIAGNOSTIC_IGNORE_STRINGOP_TRUNCATION
     87  1.1  christos #endif
     88  1.1  christos 
     89  1.1  christos #endif /* DIAGNOSTICS_H */
     90