Conditionally removes usage of deprecated features

-add macros to test for C++ version and features
to catch_compiler_capabilities.hpp
- replaces dynamic exception specifications (deprecated)
with noexcept in C++ Version >= 11
- defines defaulted copy constructor/move constructors/assignment
in C++ Version >= 11 since their implicit generation is deprecated
under some circumstances.
- fixes #259
This commit is contained in:
gnzlbg 2014-03-20 12:48:19 +01:00
parent ba13f3f098
commit ce6598599b
13 changed files with 103 additions and 10 deletions

View File

@ -41,6 +41,12 @@ 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
AssertionResult( AssertionResult const& ) = default;
AssertionResult( AssertionResult && ) = default;
AssertionResult& operator = ( AssertionResult const& ) = default;
AssertionResult& operator = ( AssertionResult && ) = default;
# endif
bool isOk() const; bool isOk() const;
bool succeeded() const; bool succeeded() const;

View File

@ -113,6 +113,11 @@ namespace Catch {
: file( other.file ), : file( other.file ),
line( other.line ) line( other.line )
{} {}
# ifdef CATCH_CPP11_OR_GREATER
SourceLineInfo( SourceLineInfo && ) = default;
SourceLineInfo& operator = ( SourceLineInfo const& ) = default;
SourceLineInfo& operator = ( SourceLineInfo && ) = default;
# endif
bool empty() const { bool empty() const {
return file.empty(); return file.empty();
} }

View File

@ -81,5 +81,27 @@
#endif #endif
////////////////////////////////////////////////////////////////////////////////
// C++ language feature support
// detect language version:
#if (__cplusplus == 201103L)
# define CATCH_CPP11
# define CATCH_CPP11_OR_GREATER
#elif (__cplusplus >= 201103L)
# define CATCH_CPP11_OR_GREATER
#endif
// noexcept support:
#ifdef CATCH_CPP11_OR_GREATER
# if (__has_feature(cxx_noexcept))
# define CATCH_NOEXCEPT noexcept
# define CATCH_NOEXCEPT_IS(x) noexcept(x)
# endif
#else
# define CATCH_NOEXCEPT throw()
# define CATCH_NOEXCEPT_IS(x)
#endif
#endif // TWOBLUECUBES_CATCH_COMPILER_CAPABILITIES_HPP_INCLUDED #endif // TWOBLUECUBES_CATCH_COMPILER_CAPABILITIES_HPP_INCLUDED

View File

@ -14,14 +14,21 @@
namespace Catch { namespace Catch {
// Wraps the LHS of an expression and captures the operator and RHS (if any) - wrapping them all // Wraps the LHS of an expression and captures the operator and RHS (if any) -
// in an ExpressionResultBuilder object // wrapping them all in an ExpressionResultBuilder object
template<typename T> template<typename T>
class ExpressionLhs { class ExpressionLhs {
void operator = ( ExpressionLhs const& ); ExpressionLhs& operator = ( ExpressionLhs const& );
# ifdef CATCH_CPP11_OR_GREATER
ExpressionLhs& operator = ( ExpressionLhs && ) = delete;
# endif
public: public:
ExpressionLhs( T lhs ) : m_lhs( lhs ) {} ExpressionLhs( T lhs ) : m_lhs( lhs ) {}
# ifdef CATCH_CPP11_OR_GREATER
ExpressionLhs( ExpressionLhs const& ) = default;
ExpressionLhs( ExpressionLhs && ) = default;
# endif
template<typename RhsT> template<typename RhsT>
ExpressionResultBuilder& operator == ( RhsT const& rhs ) { ExpressionResultBuilder& operator == ( RhsT const& rhs ) {

View File

@ -39,7 +39,7 @@
namespace Catch { namespace Catch {
NonCopyable::~NonCopyable() {} NonCopyable::~NonCopyable() {}
IShared::~IShared() {} IShared::~IShared() {}
StreamBufBase::~StreamBufBase() throw() {} StreamBufBase::~StreamBufBase() CATCH_NOEXCEPT {}
IContext::~IContext() {} IContext::~IContext() {}
IResultCapture::~IResultCapture() {} IResultCapture::~IResultCapture() {}
ITestCase::~ITestCase() {} ITestCase::~ITestCase() {}

View File

@ -114,6 +114,13 @@ namespace Catch
} }
virtual ~AssertionStats(); virtual ~AssertionStats();
# ifdef CATCH_CPP11_OR_GREATER
AssertionStats( AssertionStats const& ) = default;
AssertionStats( AssertionStats && ) = default;
AssertionStats& operator = ( AssertionStats const& ) = default;
AssertionStats& operator = ( AssertionStats && ) = default;
# endif
AssertionResult assertionResult; AssertionResult assertionResult;
std::vector<MessageInfo> infoMessages; std::vector<MessageInfo> infoMessages;
Totals totals; Totals totals;
@ -130,6 +137,12 @@ namespace Catch
missingAssertions( _missingAssertions ) missingAssertions( _missingAssertions )
{} {}
virtual ~SectionStats(); virtual ~SectionStats();
# ifdef CATCH_CPP11_OR_GREATER
SectionStats( SectionStats const& ) = default;
SectionStats( SectionStats && ) = default;
SectionStats& operator = ( SectionStats const& ) = default;
SectionStats& operator = ( SectionStats && ) = default;
# endif
SectionInfo sectionInfo; SectionInfo sectionInfo;
Counts assertions; Counts assertions;
@ -151,6 +164,13 @@ namespace Catch
{} {}
virtual ~TestCaseStats(); virtual ~TestCaseStats();
# ifdef CATCH_CPP11_OR_GREATER
TestCaseStats( TestCaseStats const& ) = default;
TestCaseStats( TestCaseStats && ) = default;
TestCaseStats& operator = ( TestCaseStats const& ) = default;
TestCaseStats& operator = ( TestCaseStats && ) = default;
# endif
TestCaseInfo testInfo; TestCaseInfo testInfo;
Totals totals; Totals totals;
std::string stdOut; std::string stdOut;
@ -172,6 +192,13 @@ namespace Catch
{} {}
virtual ~TestGroupStats(); virtual ~TestGroupStats();
# ifdef CATCH_CPP11_OR_GREATER
TestGroupStats( TestGroupStats const& ) = default;
TestGroupStats( TestGroupStats && ) = default;
TestGroupStats& operator = ( TestGroupStats const& ) = default;
TestGroupStats& operator = ( TestGroupStats && ) = default;
# endif
GroupInfo groupInfo; GroupInfo groupInfo;
Totals totals; Totals totals;
bool aborting; bool aborting;
@ -185,12 +212,20 @@ namespace Catch
totals( _totals ), totals( _totals ),
aborting( _aborting ) aborting( _aborting )
{} {}
virtual ~TestRunStats();
# ifndef CATCH_CPP11_OR_GREATER
TestRunStats( TestRunStats const& _other ) TestRunStats( TestRunStats const& _other )
: runInfo( _other.runInfo ), : runInfo( _other.runInfo ),
totals( _other.totals ), totals( _other.totals ),
aborting( _other.aborting ) aborting( _other.aborting )
{} {}
virtual ~TestRunStats(); # else
TestRunStats( TestRunStats const& ) = default;
TestRunStats( TestRunStats && ) = default;
TestRunStats& operator = ( TestRunStats const& ) = default;
TestRunStats& operator = ( TestRunStats && ) = default;
# endif
TestRunInfo runInfo; TestRunInfo runInfo;
Totals totals; Totals totals;

View File

@ -18,9 +18,9 @@ namespace Catch {
public: public:
NotImplementedException( SourceLineInfo const& lineInfo ); NotImplementedException( SourceLineInfo const& lineInfo );
virtual ~NotImplementedException() throw() {} virtual ~NotImplementedException() CATCH_NOEXCEPT {}
virtual const char* what() const throw(); virtual const char* what() const CATCH_NOEXCEPT;
private: private:
std::string m_what; std::string m_what;

View File

@ -21,7 +21,7 @@ namespace Catch {
m_what = oss.str(); m_what = oss.str();
} }
const char* NotImplementedException::what() const throw() { const char* NotImplementedException::what() const CATCH_NOEXCEPT {
return m_what.c_str(); return m_what.c_str();
} }

View File

@ -33,6 +33,13 @@ namespace Catch {
getCurrentContext().getResultCapture().sectionEnded( m_info, m_assertions, m_timer.getElapsedSeconds() ); getCurrentContext().getResultCapture().sectionEnded( m_info, m_assertions, m_timer.getElapsedSeconds() );
} }
# ifdef CATCH_CPP11_OR_GREATER
Section( Section const& ) = default;
Section( Section && ) = default;
Section& operator = ( Section const& ) = default;
Section& operator = ( Section && ) = default;
# endif
// This indicates whether the section should be executed or not // This indicates whether the section should be executed or not
operator bool() { operator bool() {
return m_sectionIncluded; return m_sectionIncluded;

View File

@ -27,7 +27,7 @@ namespace Catch {
setp( data, data + sizeof(data) ); setp( data, data + sizeof(data) );
} }
~StreamBufImpl() throw() { ~StreamBufImpl() CATCH_NOEXCEPT {
sync(); sync();
} }

View File

@ -14,7 +14,7 @@ namespace Catch {
class StreamBufBase : public std::streambuf { class StreamBufBase : public std::streambuf {
public: public:
virtual ~StreamBufBase() throw(); virtual ~StreamBufBase() CATCH_NOEXCEPT;
}; };
} }

View File

@ -66,11 +66,18 @@ namespace Catch {
endElement(); endElement();
} }
# ifndef CATCH_CPP11_OR_GREATER
XmlWriter& operator = ( XmlWriter const& other ) { XmlWriter& operator = ( XmlWriter const& other ) {
XmlWriter temp( other ); XmlWriter temp( other );
swap( temp ); swap( temp );
return *this; return *this;
} }
# else
XmlWriter( XmlWriter const& ) = default;
XmlWriter( XmlWriter && ) = default;
XmlWriter& operator = ( XmlWriter const& ) = default;
XmlWriter& operator = ( XmlWriter && ) = default;
# endif
void swap( XmlWriter& other ) { void swap( XmlWriter& other ) {
std::swap( m_tagIsOpen, other.m_tagIsOpen ); std::swap( m_tagIsOpen, other.m_tagIsOpen );

View File

@ -52,6 +52,10 @@ namespace Clara {
template<typename ConfigT> template<typename ConfigT>
struct IArgFunction { struct IArgFunction {
virtual ~IArgFunction() {} virtual ~IArgFunction() {}
# ifdef CATCH_CPP11_OR_GREATER
IArgFunction() = default;
IArgFunction( IArgFunction const& ) = default;
# endif
virtual void set( ConfigT& config, std::string const& value ) const = 0; virtual void set( ConfigT& config, std::string const& value ) const = 0;
virtual void setFlag( ConfigT& config ) const = 0; virtual void setFlag( ConfigT& config ) const = 0;
virtual bool takesArg() const = 0; virtual bool takesArg() const = 0;