blob: ed4aa52b92f764486af8a6fc06ed539d87d0e918 [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)
Phil Nashe86daf82015-05-19 18:37:58 +010022
23// CATCH_CONFIG_CPP11_OR_GREATER : Is C++11 supported?
24
Phil Nashe86daf82015-05-19 18:37:58 +010025// CATCH_CONFIG_VARIADIC_MACROS : are variadic macros supported?
Phil Nash13a887a2015-12-15 07:50:51 +000026// CATCH_CONFIG_COUNTER : is the __COUNTER__ macro supported?
Phil Nash40d0d2f2015-08-11 08:09:41 +010027// ****************
28// Note to maintainers: if new toggles are added please document them
29// in configuration.md, too
30// ****************
Phil Nashe86daf82015-05-19 18:37:58 +010031
Phil Nash7ab3b5a2015-06-30 08:41:55 +010032// In general each macro has a _NO_<feature name> form
33// (e.g. CATCH_CONFIG_CPP11_NO_NULLPTR) which disables the feature.
34// Many features, at point of detection, define an _INTERNAL_ macro, so they
35// can be combined, en-mass, with the _NO_ forms later.
36
37// All the C++11 features can be disabled with CATCH_CONFIG_NO_CPP11
Phil Nash5062d3e2013-04-16 22:55:31 +010038
Phil Nash91bfe682016-02-29 08:01:06 +000039#if defined(__cplusplus) && __cplusplus >= 201103L
40# define CATCH_CPP11_OR_GREATER
41#endif
42
Phil Nash563429d2013-12-14 14:32:26 +000043#ifdef __clang__
Phil Nash563429d2013-12-14 14:32:26 +000044
Phil Nash1a6f2a02014-04-23 18:19:19 +010045# if __has_feature(cxx_nullptr)
Phil Nash7ab3b5a2015-06-30 08:41:55 +010046# define CATCH_INTERNAL_CONFIG_CPP11_NULLPTR
Phil Nash1a6f2a02014-04-23 18:19:19 +010047# endif
Phil Nash563429d2013-12-14 14:32:26 +000048
Phil Nash1a6f2a02014-04-23 18:19:19 +010049# if __has_feature(cxx_noexcept)
Phil Nash7ab3b5a2015-06-30 08:41:55 +010050# define CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT
Phil Nash1a6f2a02014-04-23 18:19:19 +010051# endif
Phil Nash563429d2013-12-14 14:32:26 +000052
Phil Nash91bfe682016-02-29 08:01:06 +000053# if defined(CATCH_CPP11_OR_GREATER)
54# define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS _Pragma( "clang diagnostic ignored \"-Wparentheses\"" )
55# endif
56
Phil Nash563429d2013-12-14 14:32:26 +000057#endif // __clang__
58
Phil Nash5062d3e2013-04-16 22:55:31 +010059////////////////////////////////////////////////////////////////////////////////
60// Borland
61#ifdef __BORLANDC__
62
Phil Nash5062d3e2013-04-16 22:55:31 +010063
64#endif // __BORLANDC__
65
66////////////////////////////////////////////////////////////////////////////////
67// EDG
68#ifdef __EDG_VERSION__
69
Phil Nash5062d3e2013-04-16 22:55:31 +010070
71#endif // __EDG_VERSION__
72
73////////////////////////////////////////////////////////////////////////////////
74// Digital Mars
75#ifdef __DMC__
76
Phil Nash5062d3e2013-04-16 22:55:31 +010077
78#endif // __DMC__
79
80////////////////////////////////////////////////////////////////////////////////
81// GCC
82#ifdef __GNUC__
83
Phil Nash91bfe682016-02-29 08:01:06 +000084# if __GNUC__ == 4 && __GNUC_MINOR__ >= 6 && defined(__GXX_EXPERIMENTAL_CXX0X__)
85# define CATCH_INTERNAL_CONFIG_CPP11_NULLPTR
86# endif
87
88# if !defined(CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS) && defined(CATCH_CPP11_OR_GREATER)
David Grayson97e33542016-03-04 19:24:07 -080089# define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS _Pragma( "GCC diagnostic ignored \"-Wparentheses\"" )
Phil Nash91bfe682016-02-29 08:01:06 +000090# endif
Phil Nash563429d2013-12-14 14:32:26 +000091
Phil Nashf3308ed2015-07-27 18:34:21 +010092// - otherwise more recent versions define __cplusplus >= 201103L
93// and will get picked up below
94
Phil Nash5062d3e2013-04-16 22:55:31 +010095
96#endif // __GNUC__
97
98////////////////////////////////////////////////////////////////////////////////
99// Visual C++
100#ifdef _MSC_VER
101
Phil Nash43470b22015-05-19 22:37:23 +0100102#if (_MSC_VER >= 1600)
Phil Nash7ab3b5a2015-06-30 08:41:55 +0100103# define CATCH_INTERNAL_CONFIG_CPP11_NULLPTR
Phil Nash40d0d2f2015-08-11 08:09:41 +0100104# define CATCH_INTERNAL_CONFIG_CPP11_UNIQUE_PTR
Phil Nash43470b22015-05-19 22:37:23 +0100105#endif
106
Phil Nashe86daf82015-05-19 18:37:58 +0100107#if (_MSC_VER >= 1900 ) // (VC++ 13 (VS2015))
Phil Nash7ab3b5a2015-06-30 08:41:55 +0100108#define CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT
109#define CATCH_INTERNAL_CONFIG_CPP11_GENERATED_METHODS
Phil Nashe86daf82015-05-19 18:37:58 +0100110#endif
111
Phil Nash5062d3e2013-04-16 22:55:31 +0100112#endif // _MSC_VER
113
Phil Nash40d0d2f2015-08-11 08:09:41 +0100114////////////////////////////////////////////////////////////////////////////////
115
Phil Nash4dd3f682013-04-22 08:19:17 +0100116// Use variadic macros if the compiler supports them
117#if ( defined _MSC_VER && _MSC_VER > 1400 && !defined __EDGE__) || \
118 ( defined __WAVE__ && __WAVE_HAS_VARIADICS ) || \
119 ( defined __GNUC__ && __GNUC__ >= 3 ) || \
120 ( !defined __cplusplus && __STDC_VERSION__ >= 199901L || __cplusplus >= 201103L )
Phil Nash597ed1f2013-05-14 19:31:21 +0100121
Phil Nash7ab3b5a2015-06-30 08:41:55 +0100122#define CATCH_INTERNAL_CONFIG_VARIADIC_MACROS
Phil Nash597ed1f2013-05-14 19:31:21 +0100123
Phil Nash4dd3f682013-04-22 08:19:17 +0100124#endif
Phil Nash5062d3e2013-04-16 22:55:31 +0100125
Phil Nash13a887a2015-12-15 07:50:51 +0000126// Use __COUNTER__ if the compiler supports it
127#if ( defined _MSC_VER && _MSC_VER >= 1300 ) || \
128 ( defined __GNUC__ && __GNUC__ >= 4 && __GNUC_MINOR__ >= 3 ) || \
129 ( defined __clang__ && __clang_major__ >= 3 )
130
131#define CATCH_INTERNAL_CONFIG_COUNTER
132
133#endif
Phil Nash91bfe682016-02-29 08:01:06 +0000134
gnzlbgce659852014-03-20 12:48:19 +0100135////////////////////////////////////////////////////////////////////////////////
136// C++ language feature support
137
Phil Nashe86daf82015-05-19 18:37:58 +0100138// catch all support for C++11
Phil Nash91bfe682016-02-29 08:01:06 +0000139#if defined(CATCH_CPP11_OR_GREATER)
Phil Nashe86daf82015-05-19 18:37:58 +0100140
Phil Nash7ab3b5a2015-06-30 08:41:55 +0100141# if !defined(CATCH_INTERNAL_CONFIG_CPP11_NULLPTR)
142# define CATCH_INTERNAL_CONFIG_CPP11_NULLPTR
Phil Nashe86daf82015-05-19 18:37:58 +0100143# endif
144
Phil Nash7ab3b5a2015-06-30 08:41:55 +0100145# ifndef CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT
146# define CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT
Phil Nashe86daf82015-05-19 18:37:58 +0100147# endif
148
Phil Nash7ab3b5a2015-06-30 08:41:55 +0100149# ifndef CATCH_INTERNAL_CONFIG_CPP11_GENERATED_METHODS
150# define CATCH_INTERNAL_CONFIG_CPP11_GENERATED_METHODS
Phil Nashe86daf82015-05-19 18:37:58 +0100151# endif
152
Phil Nash7ab3b5a2015-06-30 08:41:55 +0100153# ifndef CATCH_INTERNAL_CONFIG_CPP11_IS_ENUM
154# define CATCH_INTERNAL_CONFIG_CPP11_IS_ENUM
Phil Nashe86daf82015-05-19 18:37:58 +0100155# endif
156
Phil Nash7ab3b5a2015-06-30 08:41:55 +0100157# ifndef CATCH_INTERNAL_CONFIG_CPP11_TUPLE
158# define CATCH_INTERNAL_CONFIG_CPP11_TUPLE
Phil Nashe86daf82015-05-19 18:37:58 +0100159# endif
160
Phil Nash7ab3b5a2015-06-30 08:41:55 +0100161# ifndef CATCH_INTERNAL_CONFIG_VARIADIC_MACROS
162# define CATCH_INTERNAL_CONFIG_VARIADIC_MACROS
Phil Nashe86daf82015-05-19 18:37:58 +0100163# endif
164
Phil Nash733ebb62015-07-23 19:03:33 +0100165# if !defined(CATCH_INTERNAL_CONFIG_CPP11_LONG_LONG)
166# define CATCH_INTERNAL_CONFIG_CPP11_LONG_LONG
167# endif
168
Phil Nash4cb74762015-08-05 19:02:17 +0100169# if !defined(CATCH_INTERNAL_CONFIG_CPP11_OVERRIDE)
170# define CATCH_INTERNAL_CONFIG_CPP11_OVERRIDE
171# endif
Phil Nash40d0d2f2015-08-11 08:09:41 +0100172# if !defined(CATCH_INTERNAL_CONFIG_CPP11_UNIQUE_PTR)
173# define CATCH_INTERNAL_CONFIG_CPP11_UNIQUE_PTR
174# endif
Phil Nash4cb74762015-08-05 19:02:17 +0100175
176
Phil Nashe86daf82015-05-19 18:37:58 +0100177#endif // __cplusplus >= 201103L
gnzlbgce659852014-03-20 12:48:19 +0100178
Phil Nash7ab3b5a2015-06-30 08:41:55 +0100179// Now set the actual defines based on the above + anything the user has configured
180#if defined(CATCH_INTERNAL_CONFIG_CPP11_NULLPTR) && !defined(CATCH_CONFIG_CPP11_NO_NULLPTR) && !defined(CATCH_CONFIG_CPP11_NULLPTR) && !defined(CATCH_CONFIG_NO_CPP11)
181# define CATCH_CONFIG_CPP11_NULLPTR
182#endif
183#if defined(CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT) && !defined(CATCH_CONFIG_CPP11_NO_NOEXCEPT) && !defined(CATCH_CONFIG_CPP11_NOEXCEPT) && !defined(CATCH_CONFIG_NO_CPP11)
184# define CATCH_CONFIG_CPP11_NOEXCEPT
185#endif
186#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)
187# define CATCH_CONFIG_CPP11_GENERATED_METHODS
188#endif
189#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)
190# define CATCH_CONFIG_CPP11_IS_ENUM
191#endif
192#if defined(CATCH_INTERNAL_CONFIG_CPP11_TUPLE) && !defined(CATCH_CONFIG_CPP11_NO_TUPLE) && !defined(CATCH_CONFIG_CPP11_TUPLE) && !defined(CATCH_CONFIG_NO_CPP11)
193# define CATCH_CONFIG_CPP11_TUPLE
194#endif
195#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 +0100196# define CATCH_CONFIG_VARIADIC_MACROS
197#endif
Phil Nash40d0d2f2015-08-11 08:09:41 +0100198#if defined(CATCH_INTERNAL_CONFIG_CPP11_LONG_LONG) && !defined(CATCH_CONFIG_NO_LONG_LONG) && !defined(CATCH_CONFIG_CPP11_LONG_LONG) && !defined(CATCH_CONFIG_NO_CPP11)
Phil Nash733ebb62015-07-23 19:03:33 +0100199# define CATCH_CONFIG_CPP11_LONG_LONG
Phil Nash7ab3b5a2015-06-30 08:41:55 +0100200#endif
Phil Nash40d0d2f2015-08-11 08:09:41 +0100201#if defined(CATCH_INTERNAL_CONFIG_CPP11_OVERRIDE) && !defined(CATCH_CONFIG_NO_OVERRIDE) && !defined(CATCH_CONFIG_CPP11_OVERRIDE) && !defined(CATCH_CONFIG_NO_CPP11)
Phil Nash4cb74762015-08-05 19:02:17 +0100202# define CATCH_CONFIG_CPP11_OVERRIDE
203#endif
Phil Nash40d0d2f2015-08-11 08:09:41 +0100204#if defined(CATCH_INTERNAL_CONFIG_CPP11_UNIQUE_PTR) && !defined(CATCH_CONFIG_NO_UNIQUE_PTR) && !defined(CATCH_CONFIG_CPP11_UNIQUE_PTR) && !defined(CATCH_CONFIG_NO_CPP11)
205# define CATCH_CONFIG_CPP11_UNIQUE_PTR
206#endif
Phil Nash13a887a2015-12-15 07:50:51 +0000207#if defined(CATCH_INTERNAL_CONFIG_COUNTER) && !defined(CATCH_CONFIG_NO_COUNTER) && !defined(CATCH_CONFIG_COUNTER)
208# define CATCH_CONFIG_COUNTER
209#endif
Phil Nash7ab3b5a2015-06-30 08:41:55 +0100210
Phil Nash91bfe682016-02-29 08:01:06 +0000211#if !defined(CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS)
212# define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS
213#endif
Phil Nash7ab3b5a2015-06-30 08:41:55 +0100214
gnzlbgce659852014-03-20 12:48:19 +0100215// noexcept support:
Phil Nash1a6f2a02014-04-23 18:19:19 +0100216#if defined(CATCH_CONFIG_CPP11_NOEXCEPT) && !defined(CATCH_NOEXCEPT)
217# define CATCH_NOEXCEPT noexcept
218# define CATCH_NOEXCEPT_IS(x) noexcept(x)
219#else
gnzlbgce659852014-03-20 12:48:19 +0100220# define CATCH_NOEXCEPT throw()
221# define CATCH_NOEXCEPT_IS(x)
222#endif
223
Phil Nash805de432015-07-01 07:33:27 +0100224// nullptr support
225#ifdef CATCH_CONFIG_CPP11_NULLPTR
226# define CATCH_NULL nullptr
227#else
228# define CATCH_NULL NULL
229#endif
Phil Nash7ab3b5a2015-06-30 08:41:55 +0100230
Phil Nash4cb74762015-08-05 19:02:17 +0100231// override support
232#ifdef CATCH_CONFIG_CPP11_OVERRIDE
233# define CATCH_OVERRIDE override
234#else
235# define CATCH_OVERRIDE
236#endif
237
Phil Nash40d0d2f2015-08-11 08:09:41 +0100238// unique_ptr support
239#ifdef CATCH_CONFIG_CPP11_UNIQUE_PTR
240# define CATCH_AUTO_PTR( T ) std::unique_ptr<T>
241#else
242# define CATCH_AUTO_PTR( T ) std::auto_ptr<T>
243#endif
244
Phil Nash5062d3e2013-04-16 22:55:31 +0100245#endif // TWOBLUECUBES_CATCH_COMPILER_CAPABILITIES_HPP_INCLUDED
246