Source:NetHack 5.0.0/include/warnings.h

From NetHackWiki
Jump to navigation Jump to search

Below is the full text to warnings.h from the source code of NetHack 5.0.0. To link to a particular line, write [[Source:NetHack 5.0.0/include/warnings.h#line12]], for example.

The NetHack General Public License applies to screenshots, source code and other content from NetHack.

This content was modified from the original NetHack source code distribution (by splitting up NetHack content between wiki pages, and possibly further editing). See the page history for a list of who changed it, and on what dates.

1. /* NetHack 5.0	warnings.h	$NHDT-Date: 1596498562 2020/08/03 23:49:22 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.24 $ */
2. /* Copyright (c) Michael Allison, 2021. */
3. 
4. #ifndef WARNINGS_H
5. #define WARNINGS_H
6. 
7. /*
8.  * If ENABLE_WARNING_PRAGMAS is defined, the checks for various
9.  * compilers is activated.
10.  *
11.  * If a suitable compiler is found, STDC_Pragma_AVAILABLE will be defined.
12.  * When STDC_Pragma_AVAILABLE is not defined, these are defined as no-ops:
13.  *     DISABLE_WARNING_UNREACHABLE_CODE
14.  *     DISABLE_WARNING_CONDEXPR_IS_CONSTANT
15.  *     DISABLE_WARNING_FORMAT_NONLITERAL
16.  *       ...
17.  *     RESTORE_WARNINGS
18.  *     RESTORE_WARNING_CONDEXPR_IS_CONSTANT
19.  *     RESTORE_WARNING_FORMAT_NONLITERAL
20.  *
21.  */
22. 
23. #if !defined(DISABLE_WARNING_PRAGMAS)
24. #if defined(__STDC_VERSION__)
25. #if __STDC_VERSION__ >= 199901L
26. #define ACTIVATE_WARNING_PRAGMAS
27. #endif /* __STDC_VERSION >= 199901L */
28. #endif /* __STDC_VERSION */
29. #if defined(_MSC_VER)
30. #ifndef ACTIVATE_WARNING_PRAGMAS
31. #define ACTIVATE_WARNING_PRAGMAS
32. #endif
33. #endif
34. #if defined(__GNUC__) || defined(__clang__)
35. #if defined(__cplusplus)
36. #ifndef ACTIVATE_WARNING_PRAGMAS
37. #define ACTIVATE_WARNING_PRAGMAS
38. #endif
39. #endif /* __cplusplus */
40. #endif /* __GNUC__ || __clang__ */
41. 
42. #ifdef ACTIVATE_WARNING_PRAGMAS
43. #if defined(__clang__)
44. #define DISABLE_WARNING_UNREACHABLE_CODE \
45.     _Pragma("clang diagnostic push")                                    \
46.     _Pragma("clang diagnostic ignored \"-Wunreachable-code\"")
47. #define DISABLE_WARNING_FORMAT_NONLITERAL \
48.     _Pragma("clang diagnostic push")                                    \
49.     _Pragma("clang diagnostic ignored \"-Wformat-nonliteral\"")
50. #define DISABLE_WARNING_CONDEXPR_IS_CONSTANT
51. #define RESTORE_WARNING_CONDEXPR_IS_CONSTANT
52. #define RESTORE_WARNING_FORMAT_NONLITERAL _Pragma("clang diagnostic pop")
53. #define RESTORE_WARNING_UNREACHABLE_CODE _Pragma("clang diagnostic pop")
54. #define RESTORE_WARNINGS _Pragma("clang diagnostic pop")
55. #define STDC_Pragma_AVAILABLE
56. 
57. #elif defined(__GNUC__)
58. /* unlike in clang, -Wunreachable-code does not function in later versions
59.    of gcc [this may be an issue of requiring -O1 or higher] */
60. #define DISABLE_WARNING_UNREACHABLE_CODE \
61.     _Pragma("GCC diagnostic push")                                      \
62.     _Pragma("GCC diagnostic ignored \"-Wunreachable-code\"")
63. #define DISABLE_WARNING_FORMAT_NONLITERAL \
64.     _Pragma("GCC diagnostic push")                                      \
65.     _Pragma("GCC diagnostic ignored \"-Wformat-nonliteral\"")
66. #define DISABLE_WARNING_CONDEXPR_IS_CONSTANT
67. #define RESTORE_WARNING_CONDEXPR_IS_CONSTANT
68. #define RESTORE_WARNING_FORMAT_NONLITERAL _Pragma("GCC diagnostic pop")
69. #define RESTORE_WARNING_UNREACHABLE_CODE _Pragma("GCC diagnostic pop")
70. #define RESTORE_WARNINGS _Pragma("GCC diagnostic pop")
71. #define STDC_Pragma_AVAILABLE
72. 
73. #elif defined(_MSC_VER)
74. #if _MSC_VER > 1916
75. #define DISABLE_WARNING_UNREACHABLE_CODE \
76.     _Pragma("warning( push )")                                  \
77.     _Pragma("warning( disable : 4702 )")
78. #define DISABLE_WARNING_FORMAT_NONLITERAL \
79.     _Pragma("warning( push )")                                  \
80.     _Pragma("warning( disable : 4774 )")
81. #define DISABLE_WARNING_CONDEXPR_IS_CONSTANT \
82.     _Pragma("warning( push )")                                  \
83.     _Pragma("warning( disable : 4127 )")
84. #define RESTORE_WARNING_CONDEXPR_IS_CONSTANT _Pragma("warning( pop )")
85. #define RESTORE_WARNING_FORMAT_NONLITERAL _Pragma("warning( pop )")
86. #define RESTORE_WARNING_UNREACHABLE_CODE _Pragma("warning( pop )")
87. #define RESTORE_WARNINGS _Pragma("warning( pop )")
88. #define STDC_Pragma_AVAILABLE
89. #else  /* Visual Studio prior to 2019 below */
90. #define DISABLE_WARNING_UNREACHABLE_CODE \
91.     __pragma(warning(push))                                     \
92.     __pragma(warning(disable:4702))
93. #define DISABLE_WARNING_FORMAT_NONLITERAL \
94.     __pragma(warning(push))                                     \
95.     __pragma(warning(disable:4774))
96. #define DISABLE_WARNING_CONDEXPR_IS_CONSTANT \
97.     __pragma(warning(push))                                     \
98.     __pragma(warning(disable:4127))
99. #define RESTORE_WARNING_CONDEXPR_IS_CONSTANT __pragma(warning(pop))
100. #define RESTORE_WARNING_FORMAT_NONLITERAL __pragma(warning(pop))
101. #define RESTORE_WARNING_UNREACHABLE_CODE __pragma(warning(pop))
102. #define RESTORE_WARNINGS  __pragma(warning(pop))
103. #define STDC_Pragma_AVAILABLE
104. #endif /* vs2019 or vs2017 */
105. 
106. #endif /* various compiler detections */
107. #endif /* ACTIVATE_WARNING_PRAGMAS */
108. #else  /* DISABLE_WARNING_PRAGMAS */
109. #if defined(STDC_Pragma_AVAILABLE)
110. #undef STDC_Pragma_AVAILABLE
111. #endif
112. #endif /* DISABLE_WARNING_PRAGMAS */
113. 
114. #if !defined(STDC_Pragma_AVAILABLE)
115. #define DISABLE_WARNING_UNREACHABLE_CODE
116. #define DISABLE_WARNING_FORMAT_NONLITERAL
117. #define DISABLE_WARNING_CONDEXPR_IS_CONSTANT
118. #define RESTORE_WARNING_CONDEXPR_IS_CONSTANT
119. #define RESTORE_WARNING_FORMAT_NONLITERAL
120. #define RESTORE_WARNING_UNREACHABLE_CODE
121. #define RESTORE_WARNINGS
122. #endif
123. 
124. #endif /* WARNINGS_H */