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 // Use of __COUNTER__ is suppressed during code analysis in CLion/AppCode 2017.2.x and former, 181 // because __COUNTER__ is not properly handled by it. 182 // This does not affect compilation 183 #if ( !defined __JETBRAINS_IDE__ || __JETBRAINS_IDE__ >= 20170300L ) 184 #define CATCH_INTERNAL_CONFIG_COUNTER 185 #endif 186 187 #endif 188 189 //////////////////////////////////////////////////////////////////////////////// 190 // C++ language feature support 191 192 // catch all support for C++11 193 #if defined(CATCH_CPP11_OR_GREATER) 194 195 # if !defined(CATCH_INTERNAL_CONFIG_CPP11_NULLPTR) 196 # define CATCH_INTERNAL_CONFIG_CPP11_NULLPTR 197 # endif 198 199 # ifndef CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT 200 # define CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT 201 # endif 202 203 # ifndef CATCH_INTERNAL_CONFIG_CPP11_GENERATED_METHODS 204 # define CATCH_INTERNAL_CONFIG_CPP11_GENERATED_METHODS 205 # endif 206 207 # ifndef CATCH_INTERNAL_CONFIG_CPP11_IS_ENUM 208 # define CATCH_INTERNAL_CONFIG_CPP11_IS_ENUM 209 # endif 210 211 # ifndef CATCH_INTERNAL_CONFIG_CPP11_TUPLE 212 # define CATCH_INTERNAL_CONFIG_CPP11_TUPLE 213 # endif 214 215 # ifndef CATCH_INTERNAL_CONFIG_VARIADIC_MACROS 216 # define CATCH_INTERNAL_CONFIG_VARIADIC_MACROS 217 # endif 218 219 # if !defined(CATCH_INTERNAL_CONFIG_CPP11_LONG_LONG) 220 # define CATCH_INTERNAL_CONFIG_CPP11_LONG_LONG 221 # endif 222 223 # if !defined(CATCH_INTERNAL_CONFIG_CPP11_OVERRIDE) 224 # define CATCH_INTERNAL_CONFIG_CPP11_OVERRIDE 225 # endif 226 # if !defined(CATCH_INTERNAL_CONFIG_CPP11_UNIQUE_PTR) 227 # define CATCH_INTERNAL_CONFIG_CPP11_UNIQUE_PTR 228 # endif 229 # if !defined(CATCH_INTERNAL_CONFIG_CPP11_SHUFFLE) 230 # define CATCH_INTERNAL_CONFIG_CPP11_SHUFFLE 231 # endif 232 # if !defined(CATCH_INTERNAL_CONFIG_CPP11_TYPE_TRAITS) 233 # define CATCH_INTERNAL_CONFIG_CPP11_TYPE_TRAITS 234 # endif 235 236 #endif // __cplusplus >= 201103L 237 238 // Now set the actual defines based on the above + anything the user has configured 239 #if defined(CATCH_INTERNAL_CONFIG_CPP11_NULLPTR) && !defined(CATCH_CONFIG_CPP11_NO_NULLPTR) && !defined(CATCH_CONFIG_CPP11_NULLPTR) && !defined(CATCH_CONFIG_NO_CPP11) 240 # define CATCH_CONFIG_CPP11_NULLPTR 241 #endif 242 #if defined(CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT) && !defined(CATCH_CONFIG_CPP11_NO_NOEXCEPT) && !defined(CATCH_CONFIG_CPP11_NOEXCEPT) && !defined(CATCH_CONFIG_NO_CPP11) 243 # define CATCH_CONFIG_CPP11_NOEXCEPT 244 #endif 245 #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) 246 # define CATCH_CONFIG_CPP11_GENERATED_METHODS 247 #endif 248 #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) 249 # define CATCH_CONFIG_CPP11_IS_ENUM 250 #endif 251 #if defined(CATCH_INTERNAL_CONFIG_CPP11_TUPLE) && !defined(CATCH_CONFIG_CPP11_NO_TUPLE) && !defined(CATCH_CONFIG_CPP11_TUPLE) && !defined(CATCH_CONFIG_NO_CPP11) 252 # define CATCH_CONFIG_CPP11_TUPLE 253 #endif 254 #if defined(CATCH_INTERNAL_CONFIG_VARIADIC_MACROS) && !defined(CATCH_CONFIG_NO_VARIADIC_MACROS) && !defined(CATCH_CONFIG_VARIADIC_MACROS) 255 # define CATCH_CONFIG_VARIADIC_MACROS 256 #endif 257 #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) 258 # define CATCH_CONFIG_CPP11_LONG_LONG 259 #endif 260 #if defined(CATCH_INTERNAL_CONFIG_CPP11_OVERRIDE) && !defined(CATCH_CONFIG_CPP11_NO_OVERRIDE) && !defined(CATCH_CONFIG_CPP11_OVERRIDE) && !defined(CATCH_CONFIG_NO_CPP11) 261 # define CATCH_CONFIG_CPP11_OVERRIDE 262 #endif 263 #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) 264 # define CATCH_CONFIG_CPP11_UNIQUE_PTR 265 #endif 266 #if defined(CATCH_INTERNAL_CONFIG_COUNTER) && !defined(CATCH_CONFIG_NO_COUNTER) && !defined(CATCH_CONFIG_COUNTER) 267 # define CATCH_CONFIG_COUNTER 268 #endif 269 #if defined(CATCH_INTERNAL_CONFIG_CPP11_SHUFFLE) && !defined(CATCH_CONFIG_CPP11_NO_SHUFFLE) && !defined(CATCH_CONFIG_CPP11_SHUFFLE) && !defined(CATCH_CONFIG_NO_CPP11) 270 # define CATCH_CONFIG_CPP11_SHUFFLE 271 #endif 272 # 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) 273 # define CATCH_CONFIG_CPP11_TYPE_TRAITS 274 # endif 275 #if defined(CATCH_INTERNAL_CONFIG_WINDOWS_SEH) && !defined(CATCH_CONFIG_NO_WINDOWS_SEH) && !defined(CATCH_CONFIG_WINDOWS_SEH) 276 # define CATCH_CONFIG_WINDOWS_SEH 277 #endif 278 // This is set by default, because we assume that unix compilers are posix-signal-compatible by default. 279 #if !defined(CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS) && !defined(CATCH_CONFIG_NO_POSIX_SIGNALS) && !defined(CATCH_CONFIG_POSIX_SIGNALS) 280 # define CATCH_CONFIG_POSIX_SIGNALS 281 #endif 282 283 #if !defined(CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS) 284 # define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS 285 # define CATCH_INTERNAL_UNSUPPRESS_PARENTHESES_WARNINGS 286 #endif 287 #if !defined(CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS) 288 # define CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS 289 # define CATCH_INTERNAL_UNSUPPRESS_ETD_WARNINGS 290 #endif 291 292 // noexcept support: 293 #if defined(CATCH_CONFIG_CPP11_NOEXCEPT) && !defined(CATCH_NOEXCEPT) 294 # define CATCH_NOEXCEPT noexcept 295 # define CATCH_NOEXCEPT_IS(x) noexcept(x) 296 #else 297 # define CATCH_NOEXCEPT throw() 298 # define CATCH_NOEXCEPT_IS(x) 299 #endif 300 301 // nullptr support 302 #ifdef CATCH_CONFIG_CPP11_NULLPTR 303 # define CATCH_NULL nullptr 304 #else 305 # define CATCH_NULL NULL 306 #endif 307 308 // override support 309 #ifdef CATCH_CONFIG_CPP11_OVERRIDE 310 # define CATCH_OVERRIDE override 311 #else 312 # define CATCH_OVERRIDE 313 #endif 314 315 // unique_ptr support 316 #ifdef CATCH_CONFIG_CPP11_UNIQUE_PTR 317 # define CATCH_AUTO_PTR( T ) std::unique_ptr<T> 318 #else 319 # define CATCH_AUTO_PTR( T ) std::auto_ptr<T> 320 #endif 321 322 #endif // TWOBLUECUBES_CATCH_COMPILER_CAPABILITIES_HPP_INCLUDED 323 324