1 /* 2 * Created by Phil on 15/04/2013. 3 * Copyright 2013 Two Blue Cubes Ltd. All rights reserved. 4 * 5 * Distributed under the Boost Software License, Version 1.0. (See accompanying 6 * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 */ 8 #ifndef TWOBLUECUBES_CATCH_COMPILER_CAPABILITIES_HPP_INCLUDED 9 #define TWOBLUECUBES_CATCH_COMPILER_CAPABILITIES_HPP_INCLUDED 10 11 // Detect a number of compiler features - by compiler 12 // The following features are defined: 13 // 14 // CATCH_CONFIG_COUNTER : is the __COUNTER__ macro supported? 15 // CATCH_CONFIG_WINDOWS_SEH : is Windows SEH supported? 16 // CATCH_CONFIG_POSIX_SIGNALS : are POSIX signals supported? 17 // CATCH_CONFIG_DISABLE_EXCEPTIONS : Are exceptions enabled? 18 // **************** 19 // Note to maintainers: if new toggles are added please document them 20 // in configuration.md, too 21 // **************** 22 23 // In general each macro has a _NO_<feature name> form 24 // (e.g. CATCH_CONFIG_NO_POSIX_SIGNALS) which disables the feature. 25 // Many features, at point of detection, define an _INTERNAL_ macro, so they 26 // can be combined, en-mass, with the _NO_ forms later. 27 28 #include "catch_platform.h" 29 30 #ifdef __cplusplus 31 32 # if (__cplusplus >= 201402L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 201402L) 33 # define CATCH_CPP14_OR_GREATER 34 # endif 35 36 # if (__cplusplus >= 201703L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) 37 # define CATCH_CPP17_OR_GREATER 38 # endif 39 40 #endif 41 42 #if defined(CATCH_CPP17_OR_GREATER) 43 # define CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS 44 #endif 45 46 // We have to avoid both ICC and Clang, because they try to mask themselves 47 // as gcc, and we want only GCC in this block 48 #if defined(__GNUC__) && !defined(__clang__) && !defined(__ICC) 49 # define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION _Pragma( "GCC diagnostic push" ) 50 # define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION _Pragma( "GCC diagnostic pop" ) 51 52 # define CATCH_INTERNAL_IGNORE_BUT_WARN(...) (void)__builtin_constant_p(__VA_ARGS__) 53 54 #endif 55 56 #if defined(__clang__) 57 58 # define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION _Pragma( "clang diagnostic push" ) 59 # define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION _Pragma( "clang diagnostic pop" ) 60 61 # define CATCH_INTERNAL_IGNORE_BUT_WARN(...) (void)__builtin_constant_p(__VA_ARGS__) 62 63 64 # define CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ 65 _Pragma( "clang diagnostic ignored \"-Wexit-time-destructors\"" ) \ 66 _Pragma( "clang diagnostic ignored \"-Wglobal-constructors\"") 67 68 # define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \ 69 _Pragma( "clang diagnostic ignored \"-Wparentheses\"" ) 70 71 # define CATCH_INTERNAL_SUPPRESS_UNUSED_WARNINGS \ 72 _Pragma( "clang diagnostic ignored \"-Wunused-variable\"" ) 73 74 # define CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS \ 75 _Pragma( "clang diagnostic ignored \"-Wgnu-zero-variadic-macro-arguments\"" ) 76 77 # define CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \ 78 _Pragma( "clang diagnostic ignored \"-Wunused-template\"" ) 79 80 #endif // __clang__ 81 82 83 //////////////////////////////////////////////////////////////////////////////// 84 // Assume that non-Windows platforms support posix signals by default 85 #if !defined(CATCH_PLATFORM_WINDOWS) 86 #define CATCH_INTERNAL_CONFIG_POSIX_SIGNALS 87 #endif 88 89 //////////////////////////////////////////////////////////////////////////////// 90 // We know some environments not to support full POSIX signals 91 #if defined(__CYGWIN__) || defined(__QNX__) || defined(__EMSCRIPTEN__) || defined(__DJGPP__) 92 #define CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS 93 #endif 94 95 #ifdef __OS400__ 96 # define CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS 97 # define CATCH_CONFIG_COLOUR_NONE 98 #endif 99 100 //////////////////////////////////////////////////////////////////////////////// 101 // Android somehow still does not support std::to_string 102 #if defined(__ANDROID__) 103 # define CATCH_INTERNAL_CONFIG_NO_CPP11_TO_STRING 104 # define CATCH_INTERNAL_CONFIG_ANDROID_LOGWRITE 105 #endif 106 107 //////////////////////////////////////////////////////////////////////////////// 108 // Not all Windows environments support SEH properly 109 #if defined(__MINGW32__) 110 # define CATCH_INTERNAL_CONFIG_NO_WINDOWS_SEH 111 #endif 112 113 //////////////////////////////////////////////////////////////////////////////// 114 // PS4 115 #if defined(__ORBIS__) 116 # define CATCH_INTERNAL_CONFIG_NO_NEW_CAPTURE 117 #endif 118 119 //////////////////////////////////////////////////////////////////////////////// 120 // Cygwin 121 #ifdef __CYGWIN__ 122 123 // Required for some versions of Cygwin to declare gettimeofday 124 // see: http://stackoverflow.com/questions/36901803/gettimeofday-not-declared-in-this-scope-cygwin 125 # define _BSD_SOURCE 126 // some versions of cygwin (most) do not support std::to_string. Use the libstd check. 127 // https://gcc.gnu.org/onlinedocs/gcc-4.8.2/libstdc++/api/a01053_source.html line 2812-2813 128 # if !((__cplusplus >= 201103L) && defined(_GLIBCXX_USE_C99) \ 129 && !defined(_GLIBCXX_HAVE_BROKEN_VSWPRINTF)) 130 131 # define CATCH_INTERNAL_CONFIG_NO_CPP11_TO_STRING 132 133 # endif 134 #endif // __CYGWIN__ 135 136 //////////////////////////////////////////////////////////////////////////////// 137 // Visual C++ 138 #if defined(_MSC_VER) 139 140 # define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION __pragma( warning(push) ) 141 # define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION __pragma( warning(pop) ) 142 143 # define CATCH_INTERNAL_IGNORE_BUT_WARN(...) (void)sizeof(__VA_ARGS__) 144 145 # if _MSC_VER >= 1900 // Visual Studio 2015 or newer 146 # define CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS 147 # endif 148 149 // Universal Windows platform does not support SEH 150 // Or console colours (or console at all...) 151 # if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_APP) 152 # define CATCH_CONFIG_COLOUR_NONE 153 # else 154 # define CATCH_INTERNAL_CONFIG_WINDOWS_SEH 155 # endif 156 157 // MSVC traditional preprocessor needs some workaround for __VA_ARGS__ 158 // _MSVC_TRADITIONAL == 0 means new conformant preprocessor 159 // _MSVC_TRADITIONAL == 1 means old traditional non-conformant preprocessor 160 # if !defined(__clang__) // Handle Clang masquerading for msvc 161 # if !defined(_MSVC_TRADITIONAL) || (defined(_MSVC_TRADITIONAL) && _MSVC_TRADITIONAL) 162 # define CATCH_INTERNAL_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR 163 # endif // MSVC_TRADITIONAL 164 # endif // __clang__ 165 166 #endif // _MSC_VER 167 168 #if defined(_REENTRANT) || defined(_MSC_VER) 169 // Enable async processing, as -pthread is specified or no additional linking is required 170 # define CATCH_INTERNAL_CONFIG_USE_ASYNC 171 #endif // _MSC_VER 172 173 //////////////////////////////////////////////////////////////////////////////// 174 // Check if we are compiled with -fno-exceptions or equivalent 175 #if defined(__EXCEPTIONS) || defined(__cpp_exceptions) || defined(_CPPUNWIND) 176 # define CATCH_INTERNAL_CONFIG_EXCEPTIONS_ENABLED 177 #endif 178 179 //////////////////////////////////////////////////////////////////////////////// 180 // DJGPP 181 #ifdef __DJGPP__ 182 # define CATCH_INTERNAL_CONFIG_NO_WCHAR 183 #endif // __DJGPP__ 184 185 //////////////////////////////////////////////////////////////////////////////// 186 // Embarcadero C++Build 187 #if defined(__BORLANDC__) 188 #define CATCH_INTERNAL_CONFIG_POLYFILL_ISNAN 189 #endif 190 191 //////////////////////////////////////////////////////////////////////////////// 192 193 // Use of __COUNTER__ is suppressed during code analysis in 194 // CLion/AppCode 2017.2.x and former, because __COUNTER__ is not properly 195 // handled by it. 196 // Otherwise all supported compilers support COUNTER macro, 197 // but user still might want to turn it off 198 #if ( !defined(__JETBRAINS_IDE__) || __JETBRAINS_IDE__ >= 20170300L ) 199 #define CATCH_INTERNAL_CONFIG_COUNTER 200 #endif 201 202 203 //////////////////////////////////////////////////////////////////////////////// 204 205 // RTX is a special version of Windows that is real time. 206 // This means that it is detected as Windows, but does not provide 207 // the same set of capabilities as real Windows does. 208 #if defined(UNDER_RTSS) || defined(RTX64_BUILD) 209 #define CATCH_INTERNAL_CONFIG_NO_WINDOWS_SEH 210 #define CATCH_INTERNAL_CONFIG_NO_ASYNC 211 #define CATCH_CONFIG_COLOUR_NONE 212 #endif 213 214 #if !defined(_GLIBCXX_USE_C99_MATH_TR1) 215 #define CATCH_INTERNAL_CONFIG_GLOBAL_NEXTAFTER 216 #endif 217 218 // Various stdlib support checks that require __has_include 219 #if defined(__has_include) 220 // Check if string_view is available and usable 221 #if __has_include(<string_view>) && defined(CATCH_CPP17_OR_GREATER) 222 # define CATCH_INTERNAL_CONFIG_CPP17_STRING_VIEW 223 #endif 224 225 // Check if optional is available and usable 226 # if __has_include(<optional>) && defined(CATCH_CPP17_OR_GREATER) 227 # define CATCH_INTERNAL_CONFIG_CPP17_OPTIONAL 228 # endif // __has_include(<optional>) && defined(CATCH_CPP17_OR_GREATER) 229 230 // Check if byte is available and usable 231 # if __has_include(<cstddef>) && defined(CATCH_CPP17_OR_GREATER) 232 # define CATCH_INTERNAL_CONFIG_CPP17_BYTE 233 # endif // __has_include(<cstddef>) && defined(CATCH_CPP17_OR_GREATER) 234 235 // Check if variant is available and usable 236 # if __has_include(<variant>) && defined(CATCH_CPP17_OR_GREATER) 237 # if defined(__clang__) && (__clang_major__ < 8) 238 // work around clang bug with libstdc++ https://bugs.llvm.org/show_bug.cgi?id=31852 239 // fix should be in clang 8, workaround in libstdc++ 8.2 240 # include <ciso646> 241 # if defined(__GLIBCXX__) && defined(_GLIBCXX_RELEASE) && (_GLIBCXX_RELEASE < 9) 242 # define CATCH_CONFIG_NO_CPP17_VARIANT 243 # else 244 # define CATCH_INTERNAL_CONFIG_CPP17_VARIANT 245 # endif // defined(__GLIBCXX__) && defined(_GLIBCXX_RELEASE) && (_GLIBCXX_RELEASE < 9) 246 # else 247 # define CATCH_INTERNAL_CONFIG_CPP17_VARIANT 248 # endif // defined(__clang__) && (__clang_major__ < 8) 249 # endif // __has_include(<variant>) && defined(CATCH_CPP17_OR_GREATER) 250 #endif // defined(__has_include) 251 252 253 #if defined(CATCH_INTERNAL_CONFIG_COUNTER) && !defined(CATCH_CONFIG_NO_COUNTER) && !defined(CATCH_CONFIG_COUNTER) 254 # define CATCH_CONFIG_COUNTER 255 #endif 256 #if defined(CATCH_INTERNAL_CONFIG_WINDOWS_SEH) && !defined(CATCH_CONFIG_NO_WINDOWS_SEH) && !defined(CATCH_CONFIG_WINDOWS_SEH) && !defined(CATCH_INTERNAL_CONFIG_NO_WINDOWS_SEH) 257 # define CATCH_CONFIG_WINDOWS_SEH 258 #endif 259 // This is set by default, because we assume that unix compilers are posix-signal-compatible by default. 260 #if defined(CATCH_INTERNAL_CONFIG_POSIX_SIGNALS) && !defined(CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS) && !defined(CATCH_CONFIG_NO_POSIX_SIGNALS) && !defined(CATCH_CONFIG_POSIX_SIGNALS) 261 # define CATCH_CONFIG_POSIX_SIGNALS 262 #endif 263 // This is set by default, because we assume that compilers with no wchar_t support are just rare exceptions. 264 #if !defined(CATCH_INTERNAL_CONFIG_NO_WCHAR) && !defined(CATCH_CONFIG_NO_WCHAR) && !defined(CATCH_CONFIG_WCHAR) 265 # define CATCH_CONFIG_WCHAR 266 #endif 267 268 #if !defined(CATCH_INTERNAL_CONFIG_NO_CPP11_TO_STRING) && !defined(CATCH_CONFIG_NO_CPP11_TO_STRING) && !defined(CATCH_CONFIG_CPP11_TO_STRING) 269 # define CATCH_CONFIG_CPP11_TO_STRING 270 #endif 271 272 #if defined(CATCH_INTERNAL_CONFIG_CPP17_OPTIONAL) && !defined(CATCH_CONFIG_NO_CPP17_OPTIONAL) && !defined(CATCH_CONFIG_CPP17_OPTIONAL) 273 # define CATCH_CONFIG_CPP17_OPTIONAL 274 #endif 275 276 #if defined(CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS) && !defined(CATCH_CONFIG_NO_CPP17_UNCAUGHT_EXCEPTIONS) && !defined(CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS) 277 # define CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS 278 #endif 279 280 #if defined(CATCH_INTERNAL_CONFIG_CPP17_STRING_VIEW) && !defined(CATCH_CONFIG_NO_CPP17_STRING_VIEW) && !defined(CATCH_CONFIG_CPP17_STRING_VIEW) 281 # define CATCH_CONFIG_CPP17_STRING_VIEW 282 #endif 283 284 #if defined(CATCH_INTERNAL_CONFIG_CPP17_VARIANT) && !defined(CATCH_CONFIG_NO_CPP17_VARIANT) && !defined(CATCH_CONFIG_CPP17_VARIANT) 285 # define CATCH_CONFIG_CPP17_VARIANT 286 #endif 287 288 #if defined(CATCH_INTERNAL_CONFIG_CPP17_BYTE) && !defined(CATCH_CONFIG_NO_CPP17_BYTE) && !defined(CATCH_CONFIG_CPP17_BYTE) 289 # define CATCH_CONFIG_CPP17_BYTE 290 #endif 291 292 293 #if defined(CATCH_CONFIG_EXPERIMENTAL_REDIRECT) 294 # define CATCH_INTERNAL_CONFIG_NEW_CAPTURE 295 #endif 296 297 #if defined(CATCH_INTERNAL_CONFIG_NEW_CAPTURE) && !defined(CATCH_INTERNAL_CONFIG_NO_NEW_CAPTURE) && !defined(CATCH_CONFIG_NO_NEW_CAPTURE) && !defined(CATCH_CONFIG_NEW_CAPTURE) 298 # define CATCH_CONFIG_NEW_CAPTURE 299 #endif 300 301 #if !defined(CATCH_INTERNAL_CONFIG_EXCEPTIONS_ENABLED) && !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS) 302 # define CATCH_CONFIG_DISABLE_EXCEPTIONS 303 #endif 304 305 #if defined(CATCH_INTERNAL_CONFIG_POLYFILL_ISNAN) && !defined(CATCH_CONFIG_NO_POLYFILL_ISNAN) && !defined(CATCH_CONFIG_POLYFILL_ISNAN) 306 # define CATCH_CONFIG_POLYFILL_ISNAN 307 #endif 308 309 #if defined(CATCH_INTERNAL_CONFIG_USE_ASYNC) && !defined(CATCH_INTERNAL_CONFIG_NO_ASYNC) && !defined(CATCH_CONFIG_NO_USE_ASYNC) && !defined(CATCH_CONFIG_USE_ASYNC) 310 # define CATCH_CONFIG_USE_ASYNC 311 #endif 312 313 #if defined(CATCH_INTERNAL_CONFIG_ANDROID_LOGWRITE) && !defined(CATCH_CONFIG_NO_ANDROID_LOGWRITE) && !defined(CATCH_CONFIG_ANDROID_LOGWRITE) 314 # define CATCH_CONFIG_ANDROID_LOGWRITE 315 #endif 316 317 #if defined(CATCH_INTERNAL_CONFIG_GLOBAL_NEXTAFTER) && !defined(CATCH_CONFIG_NO_GLOBAL_NEXTAFTER) && !defined(CATCH_CONFIG_GLOBAL_NEXTAFTER) 318 # define CATCH_CONFIG_GLOBAL_NEXTAFTER 319 #endif 320 321 322 // Even if we do not think the compiler has that warning, we still have 323 // to provide a macro that can be used by the code. 324 #if !defined(CATCH_INTERNAL_START_WARNINGS_SUPPRESSION) 325 # define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION 326 #endif 327 #if !defined(CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION) 328 # define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION 329 #endif 330 #if !defined(CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS) 331 # define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS 332 #endif 333 #if !defined(CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS) 334 # define CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS 335 #endif 336 #if !defined(CATCH_INTERNAL_SUPPRESS_UNUSED_WARNINGS) 337 # define CATCH_INTERNAL_SUPPRESS_UNUSED_WARNINGS 338 #endif 339 #if !defined(CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS) 340 # define CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS 341 #endif 342 343 // The goal of this macro is to avoid evaluation of the arguments, but 344 // still have the compiler warn on problems inside... 345 #if !defined(CATCH_INTERNAL_IGNORE_BUT_WARN) 346 # define CATCH_INTERNAL_IGNORE_BUT_WARN(...) 347 #endif 348 349 #if defined(__APPLE__) && defined(__apple_build_version__) && (__clang_major__ < 10) 350 # undef CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS 351 #elif defined(__clang__) && (__clang_major__ < 5) 352 # undef CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS 353 #endif 354 355 #if !defined(CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS) 356 # define CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS 357 #endif 358 359 #if defined(CATCH_CONFIG_DISABLE_EXCEPTIONS) 360 #define CATCH_TRY if ((true)) 361 #define CATCH_CATCH_ALL if ((false)) 362 #define CATCH_CATCH_ANON(type) if ((false)) 363 #else 364 #define CATCH_TRY try 365 #define CATCH_CATCH_ALL catch (...) 366 #define CATCH_CATCH_ANON(type) catch (type) 367 #endif 368 369 #if defined(CATCH_INTERNAL_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR) && !defined(CATCH_CONFIG_NO_TRADITIONAL_MSVC_PREPROCESSOR) && !defined(CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR) 370 #define CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR 371 #endif 372 373 #endif // TWOBLUECUBES_CATCH_COMPILER_CAPABILITIES_HPP_INCLUDED 374 375