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 - mostly C++11/14 conformance - by compiler 12 // The following features are defined: 13 // 14 // CATCH_CONFIG_CPP11_NULLPTR : is nullptr supported? 15 // CATCH_CONFIG_CPP11_NOEXCEPT : is noexcept supported? 16 // CATCH_CONFIG_CPP11_GENERATED_METHODS : The delete and default keywords for compiler generated methods 17 // CATCH_CONFIG_CPP11_IS_ENUM : std::is_enum is supported? 18 // CATCH_CONFIG_CPP11_TUPLE : std::tuple is supported 19 // CATCH_CONFIG_CPP11_LONG_LONG : is long long supported? 20 // CATCH_CONFIG_CPP11_OVERRIDE : is override supported? 21 // CATCH_CONFIG_CPP11_UNIQUE_PTR : is unique_ptr supported (otherwise use auto_ptr) 22 // CATCH_CONFIG_CPP11_SHUFFLE : is std::shuffle supported? 23 // CATCH_CONFIG_CPP11_TYPE_TRAITS : are type_traits and enable_if supported? 24 25 // CATCH_CONFIG_CPP11_OR_GREATER : Is C++11 supported? 26 27 // CATCH_CONFIG_VARIADIC_MACROS : are variadic macros supported? 28 // CATCH_CONFIG_COUNTER : is the __COUNTER__ macro supported? 29 // CATCH_CONFIG_WINDOWS_SEH : is Windows SEH supported? 30 // CATCH_CONFIG_POSIX_SIGNALS : are POSIX signals supported? 31 // **************** 32 // Note to maintainers: if new toggles are added please document them 33 // in configuration.md, too 34 // **************** 35 36 // In general each macro has a _NO_<feature name> form 37 // (e.g. CATCH_CONFIG_CPP11_NO_NULLPTR) which disables the feature. 38 // Many features, at point of detection, define an _INTERNAL_ macro, so they 39 // can be combined, en-mass, with the _NO_ forms later. 40 41 // All the C++11 features can be disabled with CATCH_CONFIG_NO_CPP11 42 43 #ifdef __cplusplus 44 45 # if __cplusplus >= 201103L 46 # define CATCH_CPP11_OR_GREATER 47 # endif 48 49 # if __cplusplus >= 201402L 50 # define CATCH_CPP14_OR_GREATER 51 # endif 52 53 #endif 54 55 #ifdef __clang__ 56 57 # if __has_feature(cxx_nullptr) 58 # define CATCH_INTERNAL_CONFIG_CPP11_NULLPTR 59 # endif 60 61 # if __has_feature(cxx_noexcept) 62 # define CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT 63 # endif 64 65 # if defined(CATCH_CPP11_OR_GREATER) 66 # define CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS \ 67 _Pragma( "clang diagnostic push" ) \ 68 _Pragma( "clang diagnostic ignored \"-Wexit-time-destructors\"" ) 69 # define CATCH_INTERNAL_UNSUPPRESS_ETD_WARNINGS \ 70 _Pragma( "clang diagnostic pop" ) 71 72 # define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \ 73 _Pragma( "clang diagnostic push" ) \ 74 _Pragma( "clang diagnostic ignored \"-Wparentheses\"" ) 75 # define CATCH_INTERNAL_UNSUPPRESS_PARENTHESES_WARNINGS \ 76 _Pragma( "clang diagnostic pop" ) 77 # endif 78 79 #endif // __clang__ 80 81 82 //////////////////////////////////////////////////////////////////////////////// 83 // We know some environments not to support full POSIX signals 84 #if defined(__CYGWIN__) || defined(__QNX__) 85 86 # if !defined(CATCH_CONFIG_POSIX_SIGNALS) 87 # define CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS 88 # endif 89 90 #endif 91 92 #ifdef __OS400__ 93 # define CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS 94 # define CATCH_CONFIG_COLOUR_NONE 95 #endif 96 97 //////////////////////////////////////////////////////////////////////////////// 98 // Cygwin 99 #ifdef __CYGWIN__ 100 101 // Required for some versions of Cygwin to declare gettimeofday 102 // see: http://stackoverflow.com/questions/36901803/gettimeofday-not-declared-in-this-scope-cygwin 103 # define _BSD_SOURCE 104 105 #endif // __CYGWIN__ 106 107 //////////////////////////////////////////////////////////////////////////////// 108 // Borland 109 #ifdef __BORLANDC__ 110 111 112 #endif // __BORLANDC__ 113 114 //////////////////////////////////////////////////////////////////////////////// 115 // EDG 116 #ifdef __EDG_VERSION__ 117 118 119 #endif // __EDG_VERSION__ 120 121 //////////////////////////////////////////////////////////////////////////////// 122 // Digital Mars 123 #ifdef __DMC__ 124 125 126 #endif // __DMC__ 127 128 //////////////////////////////////////////////////////////////////////////////// 129 // GCC 130 #ifdef __GNUC__ 131 132 # if __GNUC__ == 4 && __GNUC_MINOR__ >= 6 && defined(__GXX_EXPERIMENTAL_CXX0X__) 133 # define CATCH_INTERNAL_CONFIG_CPP11_NULLPTR 134 # endif 135 136 137 // - otherwise more recent versions define __cplusplus >= 201103L 138 // and will get picked up below 139 140 141 #endif // __GNUC__ 142 143 //////////////////////////////////////////////////////////////////////////////// 144 // Visual C++ 145 #ifdef _MSC_VER 146 147 #define CATCH_INTERNAL_CONFIG_WINDOWS_SEH 148 149 #if (_MSC_VER >= 1600) 150 # define CATCH_INTERNAL_CONFIG_CPP11_NULLPTR 151 # define CATCH_INTERNAL_CONFIG_CPP11_UNIQUE_PTR 152 #endif 153 154 #if (_MSC_VER >= 1900 ) // (VC++ 13 (VS2015)) 155 #define CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT 156 #define CATCH_INTERNAL_CONFIG_CPP11_GENERATED_METHODS 157 #define CATCH_INTERNAL_CONFIG_CPP11_SHUFFLE 158 #define CATCH_INTERNAL_CONFIG_CPP11_TYPE_TRAITS 159 #endif 160 161 #endif // _MSC_VER 162 163 //////////////////////////////////////////////////////////////////////////////// 164 165 // Use variadic macros if the compiler supports them 166 #if ( defined _MSC_VER && _MSC_VER > 1400 && !defined __EDGE__) || \ 167 ( defined __WAVE__ && __WAVE_HAS_VARIADICS ) || \ 168 ( defined __GNUC__ && __GNUC__ >= 3 ) || \ 169 ( !defined __cplusplus && __STDC_VERSION__ >= 199901L || __cplusplus >= 201103L ) 170 171 #define CATCH_INTERNAL_CONFIG_VARIADIC_MACROS 172 173 #endif 174 175 // Use __COUNTER__ if the compiler supports it 176 #if ( defined _MSC_VER && _MSC_VER >= 1300 ) || \ 177 ( defined __GNUC__ && ( __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3 )) ) || \ 178 ( defined __clang__ && __clang_major__ >= 3 ) 179 180 #define CATCH_INTERNAL_CONFIG_COUNTER 181 182 #endif 183 184 //////////////////////////////////////////////////////////////////////////////// 185 // C++ language feature support 186 187 // catch all support for C++11 188 #if defined(CATCH_CPP11_OR_GREATER) 189 190 # if !defined(CATCH_INTERNAL_CONFIG_CPP11_NULLPTR) 191 # define CATCH_INTERNAL_CONFIG_CPP11_NULLPTR 192 # endif 193 194 # ifndef CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT 195 # define CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT 196 # endif 197 198 # ifndef CATCH_INTERNAL_CONFIG_CPP11_GENERATED_METHODS 199 # define CATCH_INTERNAL_CONFIG_CPP11_GENERATED_METHODS 200 # endif 201 202 # ifndef CATCH_INTERNAL_CONFIG_CPP11_IS_ENUM 203 # define CATCH_INTERNAL_CONFIG_CPP11_IS_ENUM 204 # endif 205 206 # ifndef CATCH_INTERNAL_CONFIG_CPP11_TUPLE 207 # define CATCH_INTERNAL_CONFIG_CPP11_TUPLE 208 # endif 209 210 # ifndef CATCH_INTERNAL_CONFIG_VARIADIC_MACROS 211 # define CATCH_INTERNAL_CONFIG_VARIADIC_MACROS 212 # endif 213 214 # if !defined(CATCH_INTERNAL_CONFIG_CPP11_LONG_LONG) 215 # define CATCH_INTERNAL_CONFIG_CPP11_LONG_LONG 216 # endif 217 218 # if !defined(CATCH_INTERNAL_CONFIG_CPP11_OVERRIDE) 219 # define CATCH_INTERNAL_CONFIG_CPP11_OVERRIDE 220 # endif 221 # if !defined(CATCH_INTERNAL_CONFIG_CPP11_UNIQUE_PTR) 222 # define CATCH_INTERNAL_CONFIG_CPP11_UNIQUE_PTR 223 # endif 224 # if !defined(CATCH_INTERNAL_CONFIG_CPP11_SHUFFLE) 225 # define CATCH_INTERNAL_CONFIG_CPP11_SHUFFLE 226 # endif 227 # if !defined(CATCH_INTERNAL_CONFIG_CPP11_TYPE_TRAITS) 228 # define CATCH_INTERNAL_CONFIG_CPP11_TYPE_TRAITS 229 # endif 230 231 #endif // __cplusplus >= 201103L 232 233 // Now set the actual defines based on the above + anything the user has configured 234 #if defined(CATCH_INTERNAL_CONFIG_CPP11_NULLPTR) && !defined(CATCH_CONFIG_CPP11_NO_NULLPTR) && !defined(CATCH_CONFIG_CPP11_NULLPTR) && !defined(CATCH_CONFIG_NO_CPP11) 235 # define CATCH_CONFIG_CPP11_NULLPTR 236 #endif 237 #if defined(CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT) && !defined(CATCH_CONFIG_CPP11_NO_NOEXCEPT) && !defined(CATCH_CONFIG_CPP11_NOEXCEPT) && !defined(CATCH_CONFIG_NO_CPP11) 238 # define CATCH_CONFIG_CPP11_NOEXCEPT 239 #endif 240 #if defined(CATCH_INTERNAL_CONFIG_CPP11_GENERATED_METHODS) && !defined(CATCH_CONFIG_CPP11_NO_GENERATED_METHODS) && !defined(CATCH_CONFIG_CPP11_GENERATED_METHODS) && !defined(CATCH_CONFIG_NO_CPP11) 241 # define CATCH_CONFIG_CPP11_GENERATED_METHODS 242 #endif 243 #if defined(CATCH_INTERNAL_CONFIG_CPP11_IS_ENUM) && !defined(CATCH_CONFIG_CPP11_NO_IS_ENUM) && !defined(CATCH_CONFIG_CPP11_IS_ENUM) && !defined(CATCH_CONFIG_NO_CPP11) 244 # define CATCH_CONFIG_CPP11_IS_ENUM 245 #endif 246 #if defined(CATCH_INTERNAL_CONFIG_CPP11_TUPLE) && !defined(CATCH_CONFIG_CPP11_NO_TUPLE) && !defined(CATCH_CONFIG_CPP11_TUPLE) && !defined(CATCH_CONFIG_NO_CPP11) 247 # define CATCH_CONFIG_CPP11_TUPLE 248 #endif 249 #if defined(CATCH_INTERNAL_CONFIG_VARIADIC_MACROS) && !defined(CATCH_CONFIG_NO_VARIADIC_MACROS) && !defined(CATCH_CONFIG_VARIADIC_MACROS) 250 # define CATCH_CONFIG_VARIADIC_MACROS 251 #endif 252 #if defined(CATCH_INTERNAL_CONFIG_CPP11_LONG_LONG) && !defined(CATCH_CONFIG_CPP11_NO_LONG_LONG) && !defined(CATCH_CONFIG_CPP11_LONG_LONG) && !defined(CATCH_CONFIG_NO_CPP11) 253 # define CATCH_CONFIG_CPP11_LONG_LONG 254 #endif 255 #if defined(CATCH_INTERNAL_CONFIG_CPP11_OVERRIDE) && !defined(CATCH_CONFIG_CPP11_NO_OVERRIDE) && !defined(CATCH_CONFIG_CPP11_OVERRIDE) && !defined(CATCH_CONFIG_NO_CPP11) 256 # define CATCH_CONFIG_CPP11_OVERRIDE 257 #endif 258 #if defined(CATCH_INTERNAL_CONFIG_CPP11_UNIQUE_PTR) && !defined(CATCH_CONFIG_CPP11_NO_UNIQUE_PTR) && !defined(CATCH_CONFIG_CPP11_UNIQUE_PTR) && !defined(CATCH_CONFIG_NO_CPP11) 259 # define CATCH_CONFIG_CPP11_UNIQUE_PTR 260 #endif 261 // Use of __COUNTER__ is suppressed if __JETBRAINS_IDE__ is #defined (meaning we're being parsed by a JetBrains IDE for 262 // analytics) because, at time of writing, __COUNTER__ is not properly handled by it. 263 // This does not affect compilation 264 #if defined(CATCH_INTERNAL_CONFIG_COUNTER) && !defined(CATCH_CONFIG_NO_COUNTER) && !defined(CATCH_CONFIG_COUNTER) && !defined(__JETBRAINS_IDE__) 265 # define CATCH_CONFIG_COUNTER 266 #endif 267 #if defined(CATCH_INTERNAL_CONFIG_CPP11_SHUFFLE) && !defined(CATCH_CONFIG_CPP11_NO_SHUFFLE) && !defined(CATCH_CONFIG_CPP11_SHUFFLE) && !defined(CATCH_CONFIG_NO_CPP11) 268 # define CATCH_CONFIG_CPP11_SHUFFLE 269 #endif 270 # if defined(CATCH_INTERNAL_CONFIG_CPP11_TYPE_TRAITS) && !defined(CATCH_CONFIG_CPP11_NO_TYPE_TRAITS) && !defined(CATCH_CONFIG_CPP11_TYPE_TRAITS) && !defined(CATCH_CONFIG_NO_CPP11) 271 # define CATCH_CONFIG_CPP11_TYPE_TRAITS 272 # endif 273 #if defined(CATCH_INTERNAL_CONFIG_WINDOWS_SEH) && !defined(CATCH_CONFIG_NO_WINDOWS_SEH) && !defined(CATCH_CONFIG_WINDOWS_SEH) 274 # define CATCH_CONFIG_WINDOWS_SEH 275 #endif 276 // This is set by default, because we assume that unix compilers are posix-signal-compatible by default. 277 #if !defined(CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS) && !defined(CATCH_CONFIG_NO_POSIX_SIGNALS) && !defined(CATCH_CONFIG_POSIX_SIGNALS) 278 # define CATCH_CONFIG_POSIX_SIGNALS 279 #endif 280 281 #if !defined(CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS) 282 # define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS 283 # define CATCH_INTERNAL_UNSUPPRESS_PARENTHESES_WARNINGS 284 #endif 285 #if !defined(CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS) 286 # define CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS 287 # define CATCH_INTERNAL_UNSUPPRESS_ETD_WARNINGS 288 #endif 289 290 // noexcept support: 291 #if defined(CATCH_CONFIG_CPP11_NOEXCEPT) && !defined(CATCH_NOEXCEPT) 292 # define CATCH_NOEXCEPT noexcept 293 # define CATCH_NOEXCEPT_IS(x) noexcept(x) 294 #else 295 # define CATCH_NOEXCEPT throw() 296 # define CATCH_NOEXCEPT_IS(x) 297 #endif 298 299 // nullptr support 300 #ifdef CATCH_CONFIG_CPP11_NULLPTR 301 # define CATCH_NULL nullptr 302 #else 303 # define CATCH_NULL NULL 304 #endif 305 306 // override support 307 #ifdef CATCH_CONFIG_CPP11_OVERRIDE 308 # define CATCH_OVERRIDE override 309 #else 310 # define CATCH_OVERRIDE 311 #endif 312 313 // unique_ptr support 314 #ifdef CATCH_CONFIG_CPP11_UNIQUE_PTR 315 # define CATCH_AUTO_PTR( T ) std::unique_ptr<T> 316 #else 317 # define CATCH_AUTO_PTR( T ) std::auto_ptr<T> 318 #endif 319 320 #endif // TWOBLUECUBES_CATCH_COMPILER_CAPABILITIES_HPP_INCLUDED 321 322