Cppcheck
config.h
Go to the documentation of this file.
1 /*
2  * Cppcheck - A tool for static C/C++ code analysis
3  * Copyright (C) 2007-2024 Cppcheck team.
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program 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
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef configH
20 #define configH
21 
22 #ifdef MAXTIME
23 #error "MAXTIME is no longer supported - please use command-line options --checks-max-time=, --template-max-time= and --typedef-max-time= instead"
24 #endif
25 
26 #ifdef _WIN32
27 # ifdef CPPCHECKLIB_EXPORT
28 # define CPPCHECKLIB __declspec(dllexport)
29 # elif defined(CPPCHECKLIB_IMPORT)
30 # define CPPCHECKLIB __declspec(dllimport)
31 # else
32 # define CPPCHECKLIB
33 # endif
34 #else
35 # define CPPCHECKLIB
36 #endif
37 
38 // MS Visual C++ memory leak debug tracing
39 #if !defined(DISABLE_CRTDBG_MAP_ALLOC) && defined(_MSC_VER) && defined(_DEBUG)
40 # define _CRTDBG_MAP_ALLOC
41 # include <crtdbg.h>
42 #endif
43 
44 // compatibility macros
45 #ifndef __has_builtin
46 #define __has_builtin(x) 0
47 #endif
48 
49 #ifndef __has_include
50 #define __has_include(x) 0
51 #endif
52 
53 #ifndef __has_cpp_attribute
54 #define __has_cpp_attribute(x) 0
55 #endif
56 
57 #ifndef __has_feature
58 #define __has_feature(x) 0
59 #endif
60 
61 // C++11 noexcept
62 #if defined(__cpp_noexcept_function_type) || \
63  (defined(__GNUC__) && (__GNUC__ >= 5)) \
64  || defined(__clang__) \
65  || defined(__CPPCHECK__)
66 # define NOEXCEPT noexcept
67 #else
68 # define NOEXCEPT
69 #endif
70 
71 // C++11 noreturn
72 #if __has_cpp_attribute (noreturn) \
73  || (defined(__GNUC__) && (__GNUC__ >= 5)) \
74  || defined(__clang__) \
75  || defined(__CPPCHECK__)
76 # define NORETURN [[noreturn]]
77 #elif defined(__GNUC__)
78 # define NORETURN __attribute__((noreturn))
79 #else
80 # define NORETURN
81 #endif
82 
83 // fallthrough
84 #if __cplusplus >= 201703L && __has_cpp_attribute (fallthrough)
85 # define FALLTHROUGH [[fallthrough]]
86 #elif defined(__clang__)
87 # define FALLTHROUGH [[clang::fallthrough]]
88 #elif (defined(__GNUC__) && (__GNUC__ >= 7))
89 # define FALLTHROUGH __attribute__((fallthrough))
90 #else
91 # define FALLTHROUGH
92 #endif
93 
94 // unused
95 #if __cplusplus >= 201703L && __has_cpp_attribute (maybe_unused)
96 # define UNUSED [[maybe_unused]]
97 #elif defined(__GNUC__) \
98  || defined(__clang__) \
99  || defined(__CPPCHECK__)
100 # define UNUSED __attribute__((unused))
101 #else
102 # define UNUSED
103 #endif
104 
105 // warn_unused
106 #if __has_cpp_attribute (gnu::warn_unused) || \
107  (defined(__clang__) && (__clang_major__ >= 15))
108 # define WARN_UNUSED [[gnu::warn_unused]]
109 #else
110 # define WARN_UNUSED
111 #endif
112 
113 // deprecated
114 #if defined(__GNUC__) \
115  || defined(__clang__) \
116  || defined(__CPPCHECK__)
117 # define DEPRECATED __attribute__((deprecated))
118 #elif defined(_MSC_VER)
119 # define DEPRECATED __declspec(deprecated)
120 #else
121 # define DEPRECATED
122 #endif
123 
124 #define REQUIRES(msg, ...) class=typename std::enable_if<__VA_ARGS__::value>::type
125 
126 #include <string>
127 static const std::string emptyString;
128 
129 // Use the nonneg macro when you want to assert that a variable/argument is not negative
130 #ifdef __CPPCHECK__
131 #define nonneg __cppcheck_low__(0)
132 #elif defined(NONNEG)
133 // Enable non-negative values checking
134 // TODO : investigate using annotations/contracts for stronger value checking
135 #define nonneg unsigned
136 #else
137 // Disable non-negative values checking
138 #define nonneg
139 #endif
140 
141 #if __has_feature(address_sanitizer)
142 #define ASAN 1
143 #endif
144 
145 #ifndef ASAN
146 #ifdef __SANITIZE_ADDRESS__
147 #define ASAN 1
148 #else
149 #define ASAN 0
150 #endif
151 #endif
152 
153 #if defined(_WIN32)
154 #define HAS_THREADING_MODEL_THREAD
155 #define STDCALL __stdcall
156 #elif ((defined(__GNUC__) || defined(__sun)) && !defined(__MINGW32__)) || defined(__CPPCHECK__)
157 #define HAS_THREADING_MODEL_FORK
158 #if !defined(DISALLOW_THREAD_EXECUTOR)
159 #define HAS_THREADING_MODEL_THREAD
160 #endif
161 #define STDCALL
162 #else
163 #error "No threading model defined"
164 #endif
165 
166 #define STRINGISIZE(...) #__VA_ARGS__
167 
168 #ifdef __clang__
169 #define SUPPRESS_WARNING_PUSH(warning) _Pragma("clang diagnostic push") _Pragma(STRINGISIZE(clang diagnostic ignored warning))
170 #define SUPPRESS_WARNING_POP _Pragma("clang diagnostic pop")
171 #define SUPPRESS_WARNING_GCC_PUSH(warning)
172 #define SUPPRESS_WARNING_GCC_POP
173 #define SUPPRESS_WARNING_CLANG_PUSH(warning) SUPPRESS_WARNING_PUSH(warning)
174 #define SUPPRESS_WARNING_CLANG_POP SUPPRESS_WARNING_POP
175 #elif defined(__GNUC__)
176 #define SUPPRESS_WARNING_PUSH(warning) _Pragma("GCC diagnostic push") _Pragma(STRINGISIZE(GCC diagnostic ignored warning))
177 #define SUPPRESS_WARNING_POP _Pragma("GCC diagnostic pop")
178 #define SUPPRESS_WARNING_GCC_PUSH(warning) SUPPRESS_WARNING_PUSH(warning)
179 #define SUPPRESS_WARNING_GCC_POP SUPPRESS_WARNING_POP
180 #define SUPPRESS_WARNING_CLANG_PUSH(warning)
181 #define SUPPRESS_WARNING_CLANG_POP
182 #else
183 #define SUPPRESS_WARNING_PUSH(warning)
184 #define SUPPRESS_WARNING_POP
185 #define SUPPRESS_WARNING_GCC_PUSH(warning)
186 #define SUPPRESS_WARNING_GCC_POP
187 #define SUPPRESS_WARNING_CLANG_PUSH(warning)
188 #define SUPPRESS_WARNING_CLANG_POP
189 #endif
190 
191 #if !defined(NO_WINDOWS_SEH) && defined(_WIN32) && defined(_MSC_VER)
192 #define USE_WINDOWS_SEH
193 #endif
194 
195 // TODO: __GLIBC__ is dependent on the features.h include and not a built-in compiler define, so it might be problematic to depend on it
196 #if !defined(NO_UNIX_BACKTRACE_SUPPORT) && defined(__GNUC__) && defined(__GLIBC__) && !defined(__CYGWIN__) && !defined(__MINGW32__) && !defined(__NetBSD__) && !defined(__SVR4) && !defined(__QNX__)
197 #define USE_UNIX_BACKTRACE_SUPPORT
198 #endif
199 
200 #if !defined(NO_UNIX_SIGNAL_HANDLING) && defined(__GNUC__) && !defined(__MINGW32__) && !defined(__OS2__)
201 #define USE_UNIX_SIGNAL_HANDLING
202 #endif
203 
204 #endif // configH
static const std::string emptyString
Definition: config.h:127