blob: 325ae0289341587295eddcfd91b3a252c8844868 [file] [log] [blame]
Phil Nash5062d3e2013-04-16 22:55:31 +01001/*
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
Phil Nashe86daf82015-05-19 18:37:58 +010011// 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
Phil Nash733ebb62015-07-23 19:03:33 +010019// CATCH_CONFIG_CPP11_LONG_LONG : is long long supported?
Phil Nash4cb74762015-08-05 19:02:17 +010020// CATCH_CONFIG_CPP11_OVERRIDE : is override supported?
Phil Nash40d0d2f2015-08-11 08:09:41 +010021// CATCH_CONFIG_CPP11_UNIQUE_PTR : is unique_ptr supported (otherwise use auto_ptr)
Martin Hořeňovský60a9ac72017-01-26 18:47:29 +010022// CATCH_CONFIG_CPP11_SHUFFLE : is std::shuffle supported?
23// CATCH_CONFIG_CPP11_TYPE_TRAITS : are type_traits and enable_if supported?
Phil Nashe86daf82015-05-19 18:37:58 +010024
25// CATCH_CONFIG_CPP11_OR_GREATER : Is C++11 supported?
26
Phil Nashe86daf82015-05-19 18:37:58 +010027// CATCH_CONFIG_VARIADIC_MACROS : are variadic macros supported?
Phil Nash13a887a2015-12-15 07:50:51 +000028// CATCH_CONFIG_COUNTER : is the __COUNTER__ macro supported?
Martin Hořeňovskýe991c002017-02-06 01:43:53 +010029// CATCH_CONFIG_WINDOWS_SEH : is Windows SEH supported?
Martin Hořeňovskýc6178602017-02-15 17:57:22 +010030// CATCH_CONFIG_POSIX_SIGNALS : are POSIX signals supported?
Phil Nash40d0d2f2015-08-11 08:09:41 +010031// ****************
32// Note to maintainers: if new toggles are added please document them
33// in configuration.md, too
34// ****************
Phil Nashe86daf82015-05-19 18:37:58 +010035
Phil Nash7ab3b5a2015-06-30 08:41:55 +010036// 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
Phil Nash5062d3e2013-04-16 22:55:31 +010042
Phil Nashbe3570e2016-06-09 08:15:57 +010043#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
Phil Nash91bfe682016-02-29 08:01:06 +000053#endif
54
Phil Nash563429d2013-12-14 14:32:26 +000055#ifdef __clang__
Phil Nash563429d2013-12-14 14:32:26 +000056
Phil Nash1a6f2a02014-04-23 18:19:19 +010057# if __has_feature(cxx_nullptr)
Phil Nash7ab3b5a2015-06-30 08:41:55 +010058# define CATCH_INTERNAL_CONFIG_CPP11_NULLPTR
Phil Nash1a6f2a02014-04-23 18:19:19 +010059# endif
Phil Nash563429d2013-12-14 14:32:26 +000060
Phil Nash1a6f2a02014-04-23 18:19:19 +010061# if __has_feature(cxx_noexcept)
Phil Nash7ab3b5a2015-06-30 08:41:55 +010062# define CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT
Phil Nash1a6f2a02014-04-23 18:19:19 +010063# endif
Phil Nash563429d2013-12-14 14:32:26 +000064
Phil Nash91bfe682016-02-29 08:01:06 +000065# if defined(CATCH_CPP11_OR_GREATER)
Martin Hořeňovskýc3a41e22017-03-29 20:30:59 +020066# 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
Phil Nashfe690a62017-02-15 09:38:38 +000072# 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" )
Phil Nash91bfe682016-02-29 08:01:06 +000077# endif
78
Phil Nash563429d2013-12-14 14:32:26 +000079#endif // __clang__
80
Martin Hořeňovskýc6178602017-02-15 17:57:22 +010081
82////////////////////////////////////////////////////////////////////////////////
83// Cygwin
84#ifdef __CYGWIN__
85
86# if !defined(CATCH_CONFIG_POSIX_SIGNALS)
87# define CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS
88# endif
89
Phil Nash673ec552017-03-01 15:58:57 +000090// Required for some versions of Cygwin to declare gettimeofday
91// see: http://stackoverflow.com/questions/36901803/gettimeofday-not-declared-in-this-scope-cygwin
92# define _BSD_SOURCE
93
Martin Hořeňovskýc6178602017-02-15 17:57:22 +010094#endif // __CYGWIN__
95
Phil Nash5062d3e2013-04-16 22:55:31 +010096////////////////////////////////////////////////////////////////////////////////
97// Borland
98#ifdef __BORLANDC__
99
Phil Nash5062d3e2013-04-16 22:55:31 +0100100
101#endif // __BORLANDC__
102
103////////////////////////////////////////////////////////////////////////////////
104// EDG
105#ifdef __EDG_VERSION__
106
Phil Nash5062d3e2013-04-16 22:55:31 +0100107
108#endif // __EDG_VERSION__
109
110////////////////////////////////////////////////////////////////////////////////
111// Digital Mars
112#ifdef __DMC__
113
Phil Nash5062d3e2013-04-16 22:55:31 +0100114
115#endif // __DMC__
116
117////////////////////////////////////////////////////////////////////////////////
118// GCC
119#ifdef __GNUC__
120
Phil Nash91bfe682016-02-29 08:01:06 +0000121# if __GNUC__ == 4 && __GNUC_MINOR__ >= 6 && defined(__GXX_EXPERIMENTAL_CXX0X__)
122# define CATCH_INTERNAL_CONFIG_CPP11_NULLPTR
123# endif
124
Phil Nashfe690a62017-02-15 09:38:38 +0000125
Phil Nashf3308ed2015-07-27 18:34:21 +0100126// - otherwise more recent versions define __cplusplus >= 201103L
127// and will get picked up below
128
Phil Nash5062d3e2013-04-16 22:55:31 +0100129
130#endif // __GNUC__
131
132////////////////////////////////////////////////////////////////////////////////
133// Visual C++
134#ifdef _MSC_VER
135
Martin Hořeňovskýe991c002017-02-06 01:43:53 +0100136#define CATCH_INTERNAL_CONFIG_WINDOWS_SEH
137
Phil Nash43470b22015-05-19 22:37:23 +0100138#if (_MSC_VER >= 1600)
Phil Nash7ab3b5a2015-06-30 08:41:55 +0100139# define CATCH_INTERNAL_CONFIG_CPP11_NULLPTR
Phil Nash40d0d2f2015-08-11 08:09:41 +0100140# define CATCH_INTERNAL_CONFIG_CPP11_UNIQUE_PTR
Phil Nash43470b22015-05-19 22:37:23 +0100141#endif
142
Phil Nashe86daf82015-05-19 18:37:58 +0100143#if (_MSC_VER >= 1900 ) // (VC++ 13 (VS2015))
Phil Nash7ab3b5a2015-06-30 08:41:55 +0100144#define CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT
145#define CATCH_INTERNAL_CONFIG_CPP11_GENERATED_METHODS
Martin Hořeňovský69915492017-01-07 12:58:01 +0100146#define CATCH_INTERNAL_CONFIG_CPP11_SHUFFLE
Martin Hořeňovský60a9ac72017-01-26 18:47:29 +0100147#define CATCH_INTERNAL_CONFIG_CPP11_TYPE_TRAITS
Phil Nashe86daf82015-05-19 18:37:58 +0100148#endif
149
Phil Nash5062d3e2013-04-16 22:55:31 +0100150#endif // _MSC_VER
151
Phil Nash40d0d2f2015-08-11 08:09:41 +0100152////////////////////////////////////////////////////////////////////////////////
153
Phil Nash4dd3f682013-04-22 08:19:17 +0100154// Use variadic macros if the compiler supports them
155#if ( defined _MSC_VER && _MSC_VER > 1400 && !defined __EDGE__) || \
156 ( defined __WAVE__ && __WAVE_HAS_VARIADICS ) || \
157 ( defined __GNUC__ && __GNUC__ >= 3 ) || \
158 ( !defined __cplusplus && __STDC_VERSION__ >= 199901L || __cplusplus >= 201103L )
Phil Nash597ed1f2013-05-14 19:31:21 +0100159
Phil Nash7ab3b5a2015-06-30 08:41:55 +0100160#define CATCH_INTERNAL_CONFIG_VARIADIC_MACROS
Phil Nash597ed1f2013-05-14 19:31:21 +0100161
Phil Nash4dd3f682013-04-22 08:19:17 +0100162#endif
Phil Nash5062d3e2013-04-16 22:55:31 +0100163
Phil Nash13a887a2015-12-15 07:50:51 +0000164// Use __COUNTER__ if the compiler supports it
165#if ( defined _MSC_VER && _MSC_VER >= 1300 ) || \
166 ( defined __GNUC__ && __GNUC__ >= 4 && __GNUC_MINOR__ >= 3 ) || \
167 ( defined __clang__ && __clang_major__ >= 3 )
168
169#define CATCH_INTERNAL_CONFIG_COUNTER
170
171#endif
Phil Nash91bfe682016-02-29 08:01:06 +0000172
gnzlbgce659852014-03-20 12:48:19 +0100173////////////////////////////////////////////////////////////////////////////////
174// C++ language feature support
175
Phil Nashe86daf82015-05-19 18:37:58 +0100176// catch all support for C++11
Phil Nash91bfe682016-02-29 08:01:06 +0000177#if defined(CATCH_CPP11_OR_GREATER)
Phil Nashe86daf82015-05-19 18:37:58 +0100178
Phil Nash7ab3b5a2015-06-30 08:41:55 +0100179# if !defined(CATCH_INTERNAL_CONFIG_CPP11_NULLPTR)
180# define CATCH_INTERNAL_CONFIG_CPP11_NULLPTR
Phil Nashe86daf82015-05-19 18:37:58 +0100181# endif
182
Phil Nash7ab3b5a2015-06-30 08:41:55 +0100183# ifndef CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT
184# define CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT
Phil Nashe86daf82015-05-19 18:37:58 +0100185# endif
186
Phil Nash7ab3b5a2015-06-30 08:41:55 +0100187# ifndef CATCH_INTERNAL_CONFIG_CPP11_GENERATED_METHODS
188# define CATCH_INTERNAL_CONFIG_CPP11_GENERATED_METHODS
Phil Nashe86daf82015-05-19 18:37:58 +0100189# endif
190
Phil Nash7ab3b5a2015-06-30 08:41:55 +0100191# ifndef CATCH_INTERNAL_CONFIG_CPP11_IS_ENUM
192# define CATCH_INTERNAL_CONFIG_CPP11_IS_ENUM
Phil Nashe86daf82015-05-19 18:37:58 +0100193# endif
194
Phil Nash7ab3b5a2015-06-30 08:41:55 +0100195# ifndef CATCH_INTERNAL_CONFIG_CPP11_TUPLE
196# define CATCH_INTERNAL_CONFIG_CPP11_TUPLE
Phil Nashe86daf82015-05-19 18:37:58 +0100197# endif
198
Phil Nash7ab3b5a2015-06-30 08:41:55 +0100199# ifndef CATCH_INTERNAL_CONFIG_VARIADIC_MACROS
200# define CATCH_INTERNAL_CONFIG_VARIADIC_MACROS
Phil Nashe86daf82015-05-19 18:37:58 +0100201# endif
202
Phil Nash733ebb62015-07-23 19:03:33 +0100203# if !defined(CATCH_INTERNAL_CONFIG_CPP11_LONG_LONG)
204# define CATCH_INTERNAL_CONFIG_CPP11_LONG_LONG
205# endif
206
Phil Nash4cb74762015-08-05 19:02:17 +0100207# if !defined(CATCH_INTERNAL_CONFIG_CPP11_OVERRIDE)
208# define CATCH_INTERNAL_CONFIG_CPP11_OVERRIDE
209# endif
Phil Nash40d0d2f2015-08-11 08:09:41 +0100210# if !defined(CATCH_INTERNAL_CONFIG_CPP11_UNIQUE_PTR)
211# define CATCH_INTERNAL_CONFIG_CPP11_UNIQUE_PTR
212# endif
Martin Hořeňovský69915492017-01-07 12:58:01 +0100213# if !defined(CATCH_INTERNAL_CONFIG_CPP11_SHUFFLE)
214# define CATCH_INTERNAL_CONFIG_CPP11_SHUFFLE
215# endif
Martin Hořeňovský60a9ac72017-01-26 18:47:29 +0100216# if !defined(CATCH_INTERNAL_CONFIG_CPP11_TYPE_TRAITS)
217# define CATCH_INTERNAL_CONFIG_CPP11_TYPE_TRAITS
218# endif
Phil Nash4cb74762015-08-05 19:02:17 +0100219
Phil Nashe86daf82015-05-19 18:37:58 +0100220#endif // __cplusplus >= 201103L
gnzlbgce659852014-03-20 12:48:19 +0100221
Phil Nash7ab3b5a2015-06-30 08:41:55 +0100222// Now set the actual defines based on the above + anything the user has configured
223#if defined(CATCH_INTERNAL_CONFIG_CPP11_NULLPTR) && !defined(CATCH_CONFIG_CPP11_NO_NULLPTR) && !defined(CATCH_CONFIG_CPP11_NULLPTR) && !defined(CATCH_CONFIG_NO_CPP11)
224# define CATCH_CONFIG_CPP11_NULLPTR
225#endif
226#if defined(CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT) && !defined(CATCH_CONFIG_CPP11_NO_NOEXCEPT) && !defined(CATCH_CONFIG_CPP11_NOEXCEPT) && !defined(CATCH_CONFIG_NO_CPP11)
227# define CATCH_CONFIG_CPP11_NOEXCEPT
228#endif
229#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)
230# define CATCH_CONFIG_CPP11_GENERATED_METHODS
231#endif
232#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)
233# define CATCH_CONFIG_CPP11_IS_ENUM
234#endif
235#if defined(CATCH_INTERNAL_CONFIG_CPP11_TUPLE) && !defined(CATCH_CONFIG_CPP11_NO_TUPLE) && !defined(CATCH_CONFIG_CPP11_TUPLE) && !defined(CATCH_CONFIG_NO_CPP11)
236# define CATCH_CONFIG_CPP11_TUPLE
237#endif
238#if defined(CATCH_INTERNAL_CONFIG_VARIADIC_MACROS) && !defined(CATCH_CONFIG_NO_VARIADIC_MACROS) && !defined(CATCH_CONFIG_VARIADIC_MACROS)
Phil Nash733ebb62015-07-23 19:03:33 +0100239# define CATCH_CONFIG_VARIADIC_MACROS
240#endif
Martin Hořeňovskýa1bed572017-01-10 22:54:57 +0100241#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)
Phil Nash733ebb62015-07-23 19:03:33 +0100242# define CATCH_CONFIG_CPP11_LONG_LONG
Phil Nash7ab3b5a2015-06-30 08:41:55 +0100243#endif
Martin Hořeňovskýa1bed572017-01-10 22:54:57 +0100244#if defined(CATCH_INTERNAL_CONFIG_CPP11_OVERRIDE) && !defined(CATCH_CONFIG_CPP11_NO_OVERRIDE) && !defined(CATCH_CONFIG_CPP11_OVERRIDE) && !defined(CATCH_CONFIG_NO_CPP11)
Phil Nash4cb74762015-08-05 19:02:17 +0100245# define CATCH_CONFIG_CPP11_OVERRIDE
246#endif
Martin Hořeňovskýa1bed572017-01-10 22:54:57 +0100247#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)
Phil Nash40d0d2f2015-08-11 08:09:41 +0100248# define CATCH_CONFIG_CPP11_UNIQUE_PTR
249#endif
Phil Nash750b52b2017-01-14 21:00:51 +0000250// Use of __COUNTER__ is suppressed if __JETBRAINS_IDE__ is #defined (meaning we're being parsed by a JetBrains IDE for
251// analytics) because, at time of writing, __COUNTER__ is not properly handled by it.
252// This does not affect compilation
253#if defined(CATCH_INTERNAL_CONFIG_COUNTER) && !defined(CATCH_CONFIG_NO_COUNTER) && !defined(CATCH_CONFIG_COUNTER) && !defined(__JETBRAINS_IDE__)
Phil Nash13a887a2015-12-15 07:50:51 +0000254# define CATCH_CONFIG_COUNTER
255#endif
Martin Hořeňovskýa1bed572017-01-10 22:54:57 +0100256#if defined(CATCH_INTERNAL_CONFIG_CPP11_SHUFFLE) && !defined(CATCH_CONFIG_CPP11_NO_SHUFFLE) && !defined(CATCH_CONFIG_CPP11_SHUFFLE) && !defined(CATCH_CONFIG_NO_CPP11)
Martin Hořeňovský69915492017-01-07 12:58:01 +0100257# define CATCH_CONFIG_CPP11_SHUFFLE
258#endif
Martin Hořeňovský60a9ac72017-01-26 18:47:29 +0100259# 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)
260# define CATCH_CONFIG_CPP11_TYPE_TRAITS
261# endif
Martin Hořeňovskýe991c002017-02-06 01:43:53 +0100262#if defined(CATCH_INTERNAL_CONFIG_WINDOWS_SEH) && !defined(CATCH_CONFIG_NO_WINDOWS_SEH) && !defined(CATCH_CONFIG_WINDOWS_SEH)
263# define CATCH_CONFIG_WINDOWS_SEH
264#endif
Martin Hořeňovskýc6178602017-02-15 17:57:22 +0100265// This is set by default, because we assume that unix compilers are posix-signal-compatible by default.
Martin Hořeňovskýc3a41e22017-03-29 20:30:59 +0200266#if !defined(CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS) && !defined(CATCH_CONFIG_NO_POSIX_SIGNALS) && !defined(CATCH_CONFIG_POSIX_SIGNALS)
Martin Hořeňovskýc6178602017-02-15 17:57:22 +0100267# define CATCH_CONFIG_POSIX_SIGNALS
268#endif
Phil Nash7ab3b5a2015-06-30 08:41:55 +0100269
Phil Nash91bfe682016-02-29 08:01:06 +0000270#if !defined(CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS)
271# define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS
Phil Nashfe690a62017-02-15 09:38:38 +0000272# define CATCH_INTERNAL_UNSUPPRESS_PARENTHESES_WARNINGS
Phil Nash91bfe682016-02-29 08:01:06 +0000273#endif
Martin Hořeňovskýc3a41e22017-03-29 20:30:59 +0200274#if !defined(CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS)
275# define CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS
276# define CATCH_INTERNAL_UNSUPPRESS_ETD_WARNINGS
277#endif
Phil Nash7ab3b5a2015-06-30 08:41:55 +0100278
gnzlbgce659852014-03-20 12:48:19 +0100279// noexcept support:
Phil Nash1a6f2a02014-04-23 18:19:19 +0100280#if defined(CATCH_CONFIG_CPP11_NOEXCEPT) && !defined(CATCH_NOEXCEPT)
281# define CATCH_NOEXCEPT noexcept
282# define CATCH_NOEXCEPT_IS(x) noexcept(x)
283#else
gnzlbgce659852014-03-20 12:48:19 +0100284# define CATCH_NOEXCEPT throw()
285# define CATCH_NOEXCEPT_IS(x)
286#endif
287
Phil Nash805de432015-07-01 07:33:27 +0100288// nullptr support
289#ifdef CATCH_CONFIG_CPP11_NULLPTR
290# define CATCH_NULL nullptr
291#else
292# define CATCH_NULL NULL
293#endif
Phil Nash7ab3b5a2015-06-30 08:41:55 +0100294
Phil Nash4cb74762015-08-05 19:02:17 +0100295// override support
296#ifdef CATCH_CONFIG_CPP11_OVERRIDE
297# define CATCH_OVERRIDE override
298#else
299# define CATCH_OVERRIDE
300#endif
301
Phil Nash40d0d2f2015-08-11 08:09:41 +0100302// unique_ptr support
303#ifdef CATCH_CONFIG_CPP11_UNIQUE_PTR
304# define CATCH_AUTO_PTR( T ) std::unique_ptr<T>
305#else
306# define CATCH_AUTO_PTR( T ) std::auto_ptr<T>
307#endif
308
Phil Nash5062d3e2013-04-16 22:55:31 +0100309#endif // TWOBLUECUBES_CATCH_COMPILER_CAPABILITIES_HPP_INCLUDED
310