Home | History | Annotate | Download | only in internal
      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 #ifdef __clang__
     47 
     48 #       define CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
     49             _Pragma( "clang diagnostic push" ) \
     50             _Pragma( "clang diagnostic ignored \"-Wexit-time-destructors\"" ) \
     51             _Pragma( "clang diagnostic ignored \"-Wglobal-constructors\"")
     52 #       define CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS \
     53             _Pragma( "clang diagnostic pop" )
     54 
     55 #       define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \
     56             _Pragma( "clang diagnostic push" ) \
     57             _Pragma( "clang diagnostic ignored \"-Wparentheses\"" )
     58 #       define CATCH_INTERNAL_UNSUPPRESS_PARENTHESES_WARNINGS \
     59             _Pragma( "clang diagnostic pop" )
     60 
     61 #       define CATCH_INTERNAL_SUPPRESS_UNUSED_WARNINGS \
     62             _Pragma( "clang diagnostic push" ) \
     63             _Pragma( "clang diagnostic ignored \"-Wunused-variable\"" )
     64 #       define CATCH_INTERNAL_UNSUPPRESS_UNUSED_WARNINGS \
     65             _Pragma( "clang diagnostic pop" )
     66 
     67 #endif // __clang__
     68 
     69 
     70 ////////////////////////////////////////////////////////////////////////////////
     71 // Assume that non-Windows platforms support posix signals by default
     72 #if !defined(CATCH_PLATFORM_WINDOWS)
     73     #define CATCH_INTERNAL_CONFIG_POSIX_SIGNALS
     74 #endif
     75 
     76 ////////////////////////////////////////////////////////////////////////////////
     77 // We know some environments not to support full POSIX signals
     78 #if defined(__CYGWIN__) || defined(__QNX__) || defined(__EMSCRIPTEN__) || defined(__DJGPP__)
     79     #define CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS
     80 #endif
     81 
     82 #ifdef __OS400__
     83 #       define CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS
     84 #       define CATCH_CONFIG_COLOUR_NONE
     85 #endif
     86 
     87 ////////////////////////////////////////////////////////////////////////////////
     88 // Android somehow still does not support std::to_string
     89 #if defined(__ANDROID__)
     90 #    define CATCH_INTERNAL_CONFIG_NO_CPP11_TO_STRING
     91 #endif
     92 
     93 ////////////////////////////////////////////////////////////////////////////////
     94 // Not all Windows environments support SEH properly
     95 #if defined(__MINGW32__)
     96 #    define CATCH_INTERNAL_CONFIG_NO_WINDOWS_SEH
     97 #endif
     98 
     99 ////////////////////////////////////////////////////////////////////////////////
    100 // PS4
    101 #if defined(__ORBIS__)
    102 #    define CATCH_INTERNAL_CONFIG_NO_NEW_CAPTURE
    103 #endif
    104 
    105 ////////////////////////////////////////////////////////////////////////////////
    106 // Cygwin
    107 #ifdef __CYGWIN__
    108 
    109 // Required for some versions of Cygwin to declare gettimeofday
    110 // see: http://stackoverflow.com/questions/36901803/gettimeofday-not-declared-in-this-scope-cygwin
    111 #   define _BSD_SOURCE
    112 // some versions of cygwin (most) do not support std::to_string. Use the libstd check.
    113 // https://gcc.gnu.org/onlinedocs/gcc-4.8.2/libstdc++/api/a01053_source.html line 2812-2813
    114 # if !((__cplusplus >= 201103L) && defined(_GLIBCXX_USE_C99) \
    115 	       && !defined(_GLIBCXX_HAVE_BROKEN_VSWPRINTF))
    116 
    117 #	define CATCH_INTERNAL_CONFIG_NO_CPP11_TO_STRING
    118 
    119 # endif
    120 #endif // __CYGWIN__
    121 
    122 ////////////////////////////////////////////////////////////////////////////////
    123 // Visual C++
    124 #ifdef _MSC_VER
    125 
    126 
    127 #  if _MSC_VER >= 1900 // Visual Studio 2015 or newer
    128 #    define CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS
    129 #  endif
    130 
    131 // Universal Windows platform does not support SEH
    132 // Or console colours (or console at all...)
    133 #  if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_APP)
    134 #    define CATCH_CONFIG_COLOUR_NONE
    135 #  else
    136 #    define CATCH_INTERNAL_CONFIG_WINDOWS_SEH
    137 #  endif
    138 
    139 // MSVC traditional preprocessor needs some workaround for __VA_ARGS__
    140 // _MSVC_TRADITIONAL == 0 means new conformant preprocessor
    141 // _MSVC_TRADITIONAL == 1 means old traditional non-conformant preprocessor
    142 #  if !defined(_MSVC_TRADITIONAL) || (defined(_MSVC_TRADITIONAL) && _MSVC_TRADITIONAL)
    143 #    define CATCH_INTERNAL_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
    144 #  endif
    145 
    146 #endif // _MSC_VER
    147 
    148 ////////////////////////////////////////////////////////////////////////////////
    149 // Check if we are compiled with -fno-exceptions or equivalent
    150 #if defined(__EXCEPTIONS) || defined(__cpp_exceptions) || defined(_CPPUNWIND)
    151 #  define CATCH_INTERNAL_CONFIG_EXCEPTIONS_ENABLED
    152 #endif
    153 
    154 ////////////////////////////////////////////////////////////////////////////////
    155 // DJGPP
    156 #ifdef __DJGPP__
    157 #  define CATCH_INTERNAL_CONFIG_NO_WCHAR
    158 #endif // __DJGPP__
    159 
    160 ////////////////////////////////////////////////////////////////////////////////
    161 // Embarcadero C++Build
    162 #if defined(__BORLANDC__)
    163     #define CATCH_INTERNAL_CONFIG_POLYFILL_ISNAN
    164 #endif
    165 
    166 ////////////////////////////////////////////////////////////////////////////////
    167 
    168 // Use of __COUNTER__ is suppressed during code analysis in
    169 // CLion/AppCode 2017.2.x and former, because __COUNTER__ is not properly
    170 // handled by it.
    171 // Otherwise all supported compilers support COUNTER macro,
    172 // but user still might want to turn it off
    173 #if ( !defined(__JETBRAINS_IDE__) || __JETBRAINS_IDE__ >= 20170300L )
    174     #define CATCH_INTERNAL_CONFIG_COUNTER
    175 #endif
    176 
    177 ////////////////////////////////////////////////////////////////////////////////
    178 // Check if string_view is available and usable
    179 // The check is split apart to work around v140 (VS2015) preprocessor issue...
    180 #if defined(__has_include)
    181 #if __has_include(<string_view>) && defined(CATCH_CPP17_OR_GREATER)
    182 #    define CATCH_INTERNAL_CONFIG_CPP17_STRING_VIEW
    183 #endif
    184 #endif
    185 
    186 ////////////////////////////////////////////////////////////////////////////////
    187 // Check if optional is available and usable
    188 #if defined(__has_include)
    189 #  if __has_include(<optional>) && defined(CATCH_CPP17_OR_GREATER)
    190 #    define CATCH_INTERNAL_CONFIG_CPP17_OPTIONAL
    191 #  endif // __has_include(<optional>) && defined(CATCH_CPP17_OR_GREATER)
    192 #endif // __has_include
    193 
    194 ////////////////////////////////////////////////////////////////////////////////
    195 // Check if variant is available and usable
    196 #if defined(__has_include)
    197 #  if __has_include(<variant>) && defined(CATCH_CPP17_OR_GREATER)
    198 #    if defined(__clang__) && (__clang_major__ < 8)
    199        // work around clang bug with libstdc++ https://bugs.llvm.org/show_bug.cgi?id=31852
    200        // fix should be in clang 8, workaround in libstdc++ 8.2
    201 #      include <ciso646>
    202 #      if defined(__GLIBCXX__) && defined(_GLIBCXX_RELEASE) && (_GLIBCXX_RELEASE < 9)
    203 #        define CATCH_CONFIG_NO_CPP17_VARIANT
    204 #      else
    205 #        define CATCH_INTERNAL_CONFIG_CPP17_VARIANT
    206 #      endif // defined(__GLIBCXX__) && defined(_GLIBCXX_RELEASE) && (_GLIBCXX_RELEASE < 9)
    207 #    else
    208 #      define CATCH_INTERNAL_CONFIG_CPP17_VARIANT
    209 #    endif // defined(__clang__) && (__clang_major__ < 8)
    210 #  endif // __has_include(<variant>) && defined(CATCH_CPP17_OR_GREATER)
    211 #endif // __has_include
    212 
    213 
    214 #if defined(CATCH_INTERNAL_CONFIG_COUNTER) && !defined(CATCH_CONFIG_NO_COUNTER) && !defined(CATCH_CONFIG_COUNTER)
    215 #   define CATCH_CONFIG_COUNTER
    216 #endif
    217 #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)
    218 #   define CATCH_CONFIG_WINDOWS_SEH
    219 #endif
    220 // This is set by default, because we assume that unix compilers are posix-signal-compatible by default.
    221 #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)
    222 #   define CATCH_CONFIG_POSIX_SIGNALS
    223 #endif
    224 // This is set by default, because we assume that compilers with no wchar_t support are just rare exceptions.
    225 #if !defined(CATCH_INTERNAL_CONFIG_NO_WCHAR) && !defined(CATCH_CONFIG_NO_WCHAR) && !defined(CATCH_CONFIG_WCHAR)
    226 #   define CATCH_CONFIG_WCHAR
    227 #endif
    228 
    229 #if !defined(CATCH_INTERNAL_CONFIG_NO_CPP11_TO_STRING) && !defined(CATCH_CONFIG_NO_CPP11_TO_STRING) && !defined(CATCH_CONFIG_CPP11_TO_STRING)
    230 #    define CATCH_CONFIG_CPP11_TO_STRING
    231 #endif
    232 
    233 #if defined(CATCH_INTERNAL_CONFIG_CPP17_OPTIONAL) && !defined(CATCH_CONFIG_NO_CPP17_OPTIONAL) && !defined(CATCH_CONFIG_CPP17_OPTIONAL)
    234 #  define CATCH_CONFIG_CPP17_OPTIONAL
    235 #endif
    236 
    237 #if defined(CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS) && !defined(CATCH_CONFIG_NO_CPP17_UNCAUGHT_EXCEPTIONS) && !defined(CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS)
    238 #  define CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS
    239 #endif
    240 
    241 #if defined(CATCH_INTERNAL_CONFIG_CPP17_STRING_VIEW) && !defined(CATCH_CONFIG_NO_CPP17_STRING_VIEW) && !defined(CATCH_CONFIG_CPP17_STRING_VIEW)
    242 #  define CATCH_CONFIG_CPP17_STRING_VIEW
    243 #endif
    244 
    245 #if defined(CATCH_INTERNAL_CONFIG_CPP17_VARIANT) && !defined(CATCH_CONFIG_NO_CPP17_VARIANT) && !defined(CATCH_CONFIG_CPP17_VARIANT)
    246 #  define CATCH_CONFIG_CPP17_VARIANT
    247 #endif
    248 
    249 #if defined(CATCH_CONFIG_EXPERIMENTAL_REDIRECT)
    250 #  define CATCH_INTERNAL_CONFIG_NEW_CAPTURE
    251 #endif
    252 
    253 #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)
    254 #  define CATCH_CONFIG_NEW_CAPTURE
    255 #endif
    256 
    257 #if !defined(CATCH_INTERNAL_CONFIG_EXCEPTIONS_ENABLED) && !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS)
    258 #  define CATCH_CONFIG_DISABLE_EXCEPTIONS
    259 #endif
    260 
    261 #if defined(CATCH_INTERNAL_CONFIG_POLYFILL_ISNAN) && !defined(CATCH_CONFIG_NO_POLYFILL_ISNAN) && !defined(CATCH_CONFIG_POLYFILL_ISNAN)
    262 #  define CATCH_CONFIG_POLYFILL_ISNAN
    263 #endif
    264 
    265 #if !defined(CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS)
    266 #   define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS
    267 #   define CATCH_INTERNAL_UNSUPPRESS_PARENTHESES_WARNINGS
    268 #endif
    269 #if !defined(CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS)
    270 #   define CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS
    271 #   define CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS
    272 #endif
    273 #if !defined(CATCH_INTERNAL_SUPPRESS_UNUSED_WARNINGS)
    274 #   define CATCH_INTERNAL_SUPPRESS_UNUSED_WARNINGS
    275 #   define CATCH_INTERNAL_UNSUPPRESS_UNUSED_WARNINGS
    276 #endif
    277 
    278 #if defined(CATCH_CONFIG_DISABLE_EXCEPTIONS)
    279 #define CATCH_TRY if ((true))
    280 #define CATCH_CATCH_ALL if ((false))
    281 #define CATCH_CATCH_ANON(type) if ((false))
    282 #else
    283 #define CATCH_TRY try
    284 #define CATCH_CATCH_ALL catch (...)
    285 #define CATCH_CATCH_ANON(type) catch (type)
    286 #endif
    287 
    288 #if defined(CATCH_INTERNAL_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR) && !defined(CATCH_CONFIG_NO_TRADITIONAL_MSVC_PREPROCESSOR) && !defined(CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR)
    289 #define CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
    290 #endif
    291 
    292 #endif // TWOBLUECUBES_CATCH_COMPILER_CAPABILITIES_HPP_INCLUDED
    293 
    294