Reorganised C+11 feature detection a bit

and added CATCH_CONFIG_CPP11_NULLPTR for VS2015
This commit is contained in:
Phil Nash 2015-05-19 18:37:58 +01:00
parent bfa3f863d6
commit e86daf8bdd
9 changed files with 76 additions and 45 deletions

View File

@ -222,7 +222,7 @@ Scenario: vectors can be sized and resized
<a id="scaling-up"></a> <a id="scaling-up"></a>
## Scaling up ## Scaling up
To keep the tutorial simple we put all our code in a single file. This is fine to get started - and makes jumping into Catch even quicker and easier. As you write more real world tests, though, this is not really the best approach. To keep the tutorial simple we put all our code in a single file. This is fine to get started - and makes jumping into Catch even quicker and easier. As you write more real-world tests, though, this is not really the best approach.
The requirement is that the following block of code ([or equivalent](own-main.md)): The requirement is that the following block of code ([or equivalent](own-main.md)):

View File

@ -251,7 +251,7 @@ namespace Clara {
template<typename ConfigT> template<typename ConfigT>
struct IArgFunction { struct IArgFunction {
virtual ~IArgFunction() {} virtual ~IArgFunction() {}
# ifdef CATCH_CPP11_OR_GREATER # ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS
IArgFunction() = default; IArgFunction() = default;
IArgFunction( IArgFunction const& ) = default; IArgFunction( IArgFunction const& ) = default;
# endif # endif

View File

@ -41,7 +41,7 @@ namespace Catch {
AssertionResult(); AssertionResult();
AssertionResult( AssertionInfo const& info, AssertionResultData const& data ); AssertionResult( AssertionInfo const& info, AssertionResultData const& data );
~AssertionResult(); ~AssertionResult();
# ifdef CATCH_CPP11_OR_GREATER # ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS
AssertionResult( AssertionResult const& ) = default; AssertionResult( AssertionResult const& ) = default;
AssertionResult( AssertionResult && ) = default; AssertionResult( AssertionResult && ) = default;
AssertionResult& operator = ( AssertionResult const& ) = default; AssertionResult& operator = ( AssertionResult const& ) = default;

View File

@ -24,7 +24,7 @@
namespace Catch { namespace Catch {
class NonCopyable { class NonCopyable {
#ifdef CATCH_CPP11_OR_GREATER #ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS
NonCopyable( NonCopyable const& ) = delete; NonCopyable( NonCopyable const& ) = delete;
NonCopyable( NonCopyable && ) = delete; NonCopyable( NonCopyable && ) = delete;
NonCopyable& operator = ( NonCopyable const& ) = delete; NonCopyable& operator = ( NonCopyable const& ) = delete;
@ -87,7 +87,7 @@ namespace Catch {
SourceLineInfo(); SourceLineInfo();
SourceLineInfo( char const* _file, std::size_t _line ); SourceLineInfo( char const* _file, std::size_t _line );
SourceLineInfo( SourceLineInfo const& other ); SourceLineInfo( SourceLineInfo const& other );
# ifdef CATCH_CPP11_OR_GREATER # ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS
SourceLineInfo( SourceLineInfo && ) = default; SourceLineInfo( SourceLineInfo && ) = default;
SourceLineInfo& operator = ( SourceLineInfo const& ) = default; SourceLineInfo& operator = ( SourceLineInfo const& ) = default;
SourceLineInfo& operator = ( SourceLineInfo && ) = default; SourceLineInfo& operator = ( SourceLineInfo && ) = default;

View File

@ -8,7 +8,22 @@
#ifndef TWOBLUECUBES_CATCH_COMPILER_CAPABILITIES_HPP_INCLUDED #ifndef TWOBLUECUBES_CATCH_COMPILER_CAPABILITIES_HPP_INCLUDED
#define TWOBLUECUBES_CATCH_COMPILER_CAPABILITIES_HPP_INCLUDED #define TWOBLUECUBES_CATCH_COMPILER_CAPABILITIES_HPP_INCLUDED
// Much of the following code is based on Boost (1.53) // Detect a number of compiler features - mostly C++11/14 conformance - by compiler
// The following features are defined:
//
// CATCH_CONFIG_CPP11_NULLPTR : is nullptr supported?
// CATCH_CONFIG_CPP11_NOEXCEPT : is noexcept supported?
// CATCH_CONFIG_CPP11_GENERATED_METHODS : The delete and default keywords for compiler generated methods
// CATCH_CONFIG_CPP11_IS_ENUM : std::is_enum is supported?
// CATCH_CONFIG_CPP11_TUPLE : std::tuple is supported
// CATCH_CONFIG_CPP11_OR_GREATER : Is C++11 supported?
// CATCH_CONFIG_SFINAE : is basic (C++03) SFINAE supported?
// CATCH_CONFIG_VARIADIC_MACROS : are variadic macros supported?
// A lot of this code is based on Boost (1.53)
#ifdef __clang__ #ifdef __clang__
@ -88,6 +103,13 @@
//#define CATCH_CONFIG_SFINAE // Not confirmed //#define CATCH_CONFIG_SFINAE // Not confirmed
#endif #endif
#if (_MSC_VER >= 1900 ) // (VC++ 13 (VS2015))
#define CATCH_CONFIG_CPP11_NOEXCEPT
#define CATCH_CONFIG_CPP11_GENERATED_METHODS
#define CATCH_CONFIG_CPP11_NULLPTR
//#define CATCH_CONFIG_SFINAE // Don't use, for now
#endif
#endif // _MSC_VER #endif // _MSC_VER
// Use variadic macros if the compiler supports them // Use variadic macros if the compiler supports them
@ -105,13 +127,40 @@
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// C++ language feature support // C++ language feature support
// detect language version: // catch all support for C++11
#if (__cplusplus == 201103L) #if (__cplusplus >= 201103L)
# define CATCH_CPP11
# define CATCH_CPP11_OR_GREATER # define CATCH_CPP11_OR_GREATER
#elif (__cplusplus >= 201103L)
# define CATCH_CPP11_OR_GREATER # ifndef CATCH_CONFIG_CPP11_NULLPTR
#endif # define CATCH_CONFIG_CPP11_NULLPTR
# endif
# ifndef CATCH_CONFIG_CPP11_NOEXCEPT
# define CATCH_CONFIG_CPP11_NOEXCEPT
# endif
# ifndef CATCH_CONFIG_CPP11_GENERATED_METHODS
# define CATCH_CONFIG_CPP11_GENERATED_METHODS
# endif
# ifndef CATCH_CONFIG_CPP11_IS_ENUM
# define CATCH_CONFIG_CPP11_IS_ENUM
# endif
# ifndef CATCH_CONFIG_CPP11_TUPLE
# define CATCH_CONFIG_CPP11_TUPLE
# endif
# ifndef CATCH_CONFIG_SFINAE
//# define CATCH_CONFIG_SFINAE // Don't use, for now
# endif
# ifndef CATCH_CONFIG_VARIADIC_MACROS
# define CATCH_CONFIG_VARIADIC_MACROS
# endif
#endif // __cplusplus >= 201103L
// noexcept support: // noexcept support:
#if defined(CATCH_CONFIG_CPP11_NOEXCEPT) && !defined(CATCH_NOEXCEPT) #if defined(CATCH_CONFIG_CPP11_NOEXCEPT) && !defined(CATCH_NOEXCEPT)

View File

@ -19,13 +19,13 @@ namespace Catch {
template<typename T> template<typename T>
class ExpressionLhs { class ExpressionLhs {
ExpressionLhs& operator = ( ExpressionLhs const& ); ExpressionLhs& operator = ( ExpressionLhs const& );
# ifdef CATCH_CPP11_OR_GREATER # ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS
ExpressionLhs& operator = ( ExpressionLhs && ) = delete; ExpressionLhs& operator = ( ExpressionLhs && ) = delete;
# endif # endif
public: public:
ExpressionLhs( ResultBuilder& rb, T lhs ) : m_rb( rb ), m_lhs( lhs ) {} ExpressionLhs( ResultBuilder& rb, T lhs ) : m_rb( rb ), m_lhs( lhs ) {}
# ifdef CATCH_CPP11_OR_GREATER # ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS
ExpressionLhs( ExpressionLhs const& ) = default; ExpressionLhs( ExpressionLhs const& ) = default;
ExpressionLhs( ExpressionLhs && ) = default; ExpressionLhs( ExpressionLhs && ) = default;
# endif # endif

View File

@ -101,7 +101,7 @@ namespace Catch
} }
virtual ~AssertionStats(); virtual ~AssertionStats();
# ifdef CATCH_CPP11_OR_GREATER # ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS
AssertionStats( AssertionStats const& ) = default; AssertionStats( AssertionStats const& ) = default;
AssertionStats( AssertionStats && ) = default; AssertionStats( AssertionStats && ) = default;
AssertionStats& operator = ( AssertionStats const& ) = default; AssertionStats& operator = ( AssertionStats const& ) = default;
@ -124,7 +124,7 @@ namespace Catch
missingAssertions( _missingAssertions ) missingAssertions( _missingAssertions )
{} {}
virtual ~SectionStats(); virtual ~SectionStats();
# ifdef CATCH_CPP11_OR_GREATER # ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS
SectionStats( SectionStats const& ) = default; SectionStats( SectionStats const& ) = default;
SectionStats( SectionStats && ) = default; SectionStats( SectionStats && ) = default;
SectionStats& operator = ( SectionStats const& ) = default; SectionStats& operator = ( SectionStats const& ) = default;
@ -151,7 +151,7 @@ namespace Catch
{} {}
virtual ~TestCaseStats(); virtual ~TestCaseStats();
# ifdef CATCH_CPP11_OR_GREATER # ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS
TestCaseStats( TestCaseStats const& ) = default; TestCaseStats( TestCaseStats const& ) = default;
TestCaseStats( TestCaseStats && ) = default; TestCaseStats( TestCaseStats && ) = default;
TestCaseStats& operator = ( TestCaseStats const& ) = default; TestCaseStats& operator = ( TestCaseStats const& ) = default;
@ -179,7 +179,7 @@ namespace Catch
{} {}
virtual ~TestGroupStats(); virtual ~TestGroupStats();
# ifdef CATCH_CPP11_OR_GREATER # ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS
TestGroupStats( TestGroupStats const& ) = default; TestGroupStats( TestGroupStats const& ) = default;
TestGroupStats( TestGroupStats && ) = default; TestGroupStats( TestGroupStats && ) = default;
TestGroupStats& operator = ( TestGroupStats const& ) = default; TestGroupStats& operator = ( TestGroupStats const& ) = default;
@ -201,7 +201,7 @@ namespace Catch
{} {}
virtual ~TestRunStats(); virtual ~TestRunStats();
# ifndef CATCH_CPP11_OR_GREATER # ifndef CATCH_CONFIG_CPP11_GENERATED_METHODS
TestRunStats( TestRunStats const& _other ) TestRunStats( TestRunStats const& _other )
: runInfo( _other.runInfo ), : runInfo( _other.runInfo ),
totals( _other.totals ), totals( _other.totals ),

View File

@ -21,8 +21,11 @@
#include "catch_objc_arc.hpp" #include "catch_objc_arc.hpp"
#endif #endif
#ifdef CATCH_CPP11_OR_GREATER #ifdef CATCH_CONFIG_CPP11_TUPLE
#include <tuple> #include <tuple>
#endif
#ifdef CATCH_CONFIG_CPP11_IS_ENUM
#include <type_traits> #include <type_traits>
#endif #endif
@ -105,7 +108,7 @@ namespace Detail {
#endif #endif
#if defined(CATCH_CPP11_OR_GREATER) #if defined(CATCH_CONFIG_CPP11_IS_ENUM)
template<typename T, template<typename T,
bool IsEnum = std::is_enum<T>::value bool IsEnum = std::is_enum<T>::value
> >
@ -127,7 +130,7 @@ namespace Detail {
#endif #endif
template<bool C> template<bool C>
struct StringMakerBase { struct StringMakerBase {
#if defined(CATCH_CPP11_OR_GREATER) #if defined(CATCH_CONFIG_CPP11_IS_ENUM)
template<typename T> template<typename T>
static std::string convert( T const& v ) static std::string convert( T const& v )
{ {
@ -201,7 +204,7 @@ std::string toString( std::vector<T,Allocator> const& v ) {
} }
#ifdef CATCH_CPP11_OR_GREATER #ifdef CATCH_CONFIG_CPP11_TUPLE
// toString for tuples // toString for tuples
namespace TupleDetail { namespace TupleDetail {
@ -241,7 +244,7 @@ struct StringMaker<std::tuple<Types...>> {
return os.str(); return os.str();
} }
}; };
#endif #endif // CATCH_CONFIG_CPP11_TUPLE
namespace Detail { namespace Detail {
template<typename T> template<typename T>

View File

@ -67,27 +67,6 @@ namespace Catch {
endElement(); endElement();
} }
//# ifndef CATCH_CPP11_OR_GREATER
// XmlWriter& operator = ( XmlWriter const& other ) {
// XmlWriter temp( other );
// swap( temp );
// return *this;
// }
//# else
// XmlWriter( XmlWriter const& ) = default;
// XmlWriter( XmlWriter && ) = default;
// XmlWriter& operator = ( XmlWriter const& ) = default;
// XmlWriter& operator = ( XmlWriter && ) = default;
//# endif
//
// void swap( XmlWriter& other ) {
// std::swap( m_tagIsOpen, other.m_tagIsOpen );
// std::swap( m_needsNewline, other.m_needsNewline );
// std::swap( m_tags, other.m_tags );
// std::swap( m_indent, other.m_indent );
// std::swap( m_os, other.m_os );
// }
XmlWriter& startElement( std::string const& name ) { XmlWriter& startElement( std::string const& name ) {
ensureTagClosed(); ensureTagClosed();
newlineIfNecessary(); newlineIfNecessary();