diagnostics.h 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /* Copyright (C) 2017-2020 Free Software Foundation, Inc.
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License as published by
  4. the Free Software Foundation; either version 3 of the License, or
  5. (at your option) any later version.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU General Public License for more details.
  10. You should have received a copy of the GNU General Public License
  11. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  12. #ifndef DIAGNOSTICS_H
  13. #define DIAGNOSTICS_H
  14. /* If at all possible, fix the source rather than using these macros
  15. to silence warnings. If you do use these macros be aware that
  16. you'll need to condition their use on particular compiler versions,
  17. which can be done for gcc using ansidecl.h's GCC_VERSION macro.
  18. gcc versions between 4.2 and 4.6 do not allow pragma control of
  19. diagnostics inside functions, giving a hard error if you try to use
  20. the finer control available with later versions.
  21. gcc prior to 4.2 warns about diagnostic push and pop.
  22. The other macros have restrictions too, for example gcc-5, gcc-6
  23. and gcc-7 warn that -Wstringop-truncation is unknown, unless you
  24. also add DIAGNOSTIC_IGNORE ("-Wpragma"). */
  25. #ifdef __GNUC__
  26. # define DIAGNOSTIC_PUSH _Pragma ("GCC diagnostic push")
  27. # define DIAGNOSTIC_POP _Pragma ("GCC diagnostic pop")
  28. /* Stringification. */
  29. # define DIAGNOSTIC_STRINGIFY_1(x) #x
  30. # define DIAGNOSTIC_STRINGIFY(x) DIAGNOSTIC_STRINGIFY_1 (x)
  31. # define DIAGNOSTIC_IGNORE(option) \
  32. _Pragma (DIAGNOSTIC_STRINGIFY (GCC diagnostic ignored option))
  33. #else
  34. # define DIAGNOSTIC_PUSH
  35. # define DIAGNOSTIC_POP
  36. # define DIAGNOSTIC_IGNORE(option)
  37. #endif
  38. #if defined (__clang__) /* clang */
  39. # define DIAGNOSTIC_IGNORE_SELF_MOVE DIAGNOSTIC_IGNORE ("-Wself-move")
  40. # define DIAGNOSTIC_IGNORE_DEPRECATED_DECLARATIONS \
  41. DIAGNOSTIC_IGNORE ("-Wdeprecated-declarations")
  42. # define DIAGNOSTIC_IGNORE_DEPRECATED_REGISTER \
  43. DIAGNOSTIC_IGNORE ("-Wdeprecated-register")
  44. # if __has_warning ("-Wenum-compare-switch")
  45. # define DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES \
  46. DIAGNOSTIC_IGNORE ("-Wenum-compare-switch")
  47. # endif
  48. # define DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL \
  49. DIAGNOSTIC_IGNORE ("-Wformat-nonliteral")
  50. #elif defined (__GNUC__) /* GCC */
  51. # define DIAGNOSTIC_IGNORE_STRINGOP_TRUNCATION \
  52. DIAGNOSTIC_IGNORE ("-Wstringop-truncation")
  53. # define DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL \
  54. DIAGNOSTIC_IGNORE ("-Wformat-nonliteral")
  55. #endif
  56. #ifndef DIAGNOSTIC_IGNORE_SELF_MOVE
  57. # define DIAGNOSTIC_IGNORE_SELF_MOVE
  58. #endif
  59. #ifndef DIAGNOSTIC_IGNORE_DEPRECATED_DECLARATIONS
  60. # define DIAGNOSTIC_IGNORE_DEPRECATED_DECLARATIONS
  61. #endif
  62. #ifndef DIAGNOSTIC_IGNORE_DEPRECATED_REGISTER
  63. # define DIAGNOSTIC_IGNORE_DEPRECATED_REGISTER
  64. #endif
  65. #ifndef DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
  66. # define DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
  67. #endif
  68. #ifndef DIAGNOSTIC_IGNORE_STRINGOP_TRUNCATION
  69. # define DIAGNOSTIC_IGNORE_STRINGOP_TRUNCATION
  70. #endif
  71. #ifndef DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL
  72. # define DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL
  73. #endif
  74. #endif /* DIAGNOSTICS_H */