From 23181eeef0d6fed9caff7124159b22d61427b78c Mon Sep 17 00:00:00 2001 From: Phil Nash Date: Wed, 9 Jul 2014 07:39:57 +0100 Subject: [PATCH] Section no longer relies on copy-elision for correctness - should address #293 - *may* address #271 --- include/internal/catch_runner_impl.hpp | 2 +- include/internal/catch_section.h | 26 +++++++++---------- include/internal/catch_section.hpp | 17 ++++++++---- include/internal/catch_section_info.h | 11 +++----- include/internal/catch_suppress_warnings.h | 1 + projects/SelfTest/TrickyTests.cpp | 2 +- .../CatchSelfTest.xcodeproj/project.pbxproj | 6 +++-- 7 files changed, 36 insertions(+), 29 deletions(-) diff --git a/include/internal/catch_runner_impl.hpp b/include/internal/catch_runner_impl.hpp index 79288a08..fa4f3193 100644 --- a/include/internal/catch_runner_impl.hpp +++ b/include/internal/catch_runner_impl.hpp @@ -219,7 +219,7 @@ namespace Catch { void runCurrentTest( std::string& redirectedCout, std::string& redirectedCerr ) { TestCaseInfo const& testCaseInfo = m_activeTestCase->getTestCaseInfo(); - SectionInfo testCaseSection( testCaseInfo.name, testCaseInfo.description, testCaseInfo.lineInfo ); + SectionInfo testCaseSection( testCaseInfo.lineInfo, testCaseInfo.name, testCaseInfo.description ); m_reporter->sectionStarting( testCaseSection ); Counts prevAssertions = m_totals.assertions; double duration = 0; diff --git a/include/internal/catch_section.h b/include/internal/catch_section.h index 39211ed9..f83d828b 100644 --- a/include/internal/catch_section.h +++ b/include/internal/catch_section.h @@ -18,22 +18,22 @@ namespace Catch { class Section { public: - Section( SourceLineInfo const& lineInfo, - std::string const& name, - std::string const& description = "" ); + Section( SectionInfo const& info ); ~Section(); -# 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 - operator bool(); + operator bool() const; private: - +#ifdef CATCH_CPP11_OR_GREATER + Section( Section const& ) = delete; + Section( Section && ) = delete; + Section& operator = ( Section const& ) = delete; + Section& operator = ( Section && ) = delete; +#else + Section( Section const& info ); + Section& operator = ( Section const& ); +#endif SectionInfo m_info; std::string m_name; @@ -46,10 +46,10 @@ namespace Catch { #ifdef CATCH_CONFIG_VARIADIC_MACROS #define INTERNAL_CATCH_SECTION( ... ) \ - if( Catch::Section INTERNAL_CATCH_UNIQUE_NAME( catch_internal_Section ) = Catch::Section( CATCH_INTERNAL_LINEINFO, __VA_ARGS__ ) ) + if( Catch::Section const& INTERNAL_CATCH_UNIQUE_NAME( catch_internal_Section ) = Catch::SectionInfo( CATCH_INTERNAL_LINEINFO, __VA_ARGS__ ) ) #else #define INTERNAL_CATCH_SECTION( name, desc ) \ - if( Catch::Section INTERNAL_CATCH_UNIQUE_NAME( catch_internal_Section ) = Catch::Section( CATCH_INTERNAL_LINEINFO, name, desc ) ) + if( Catch::Section const& INTERNAL_CATCH_UNIQUE_NAME( catch_internal_Section ) = Catch::SectionInfo( CATCH_INTERNAL_LINEINFO, name, desc ) ) #endif #endif // TWOBLUECUBES_CATCH_SECTION_H_INCLUDED diff --git a/include/internal/catch_section.hpp b/include/internal/catch_section.hpp index a71f75b6..ec4c1518 100644 --- a/include/internal/catch_section.hpp +++ b/include/internal/catch_section.hpp @@ -15,10 +15,17 @@ namespace Catch { - Section::Section( SourceLineInfo const& lineInfo, - std::string const& name, - std::string const& description ) - : m_info( name, description, lineInfo ), + SectionInfo::SectionInfo + ( SourceLineInfo const& _lineInfo, + std::string const& _name, + std::string const& _description ) + : name( _name ), + description( _description ), + lineInfo( _lineInfo ) + {} + + Section::Section( SectionInfo const& info ) + : m_info( info ), m_sectionIncluded( getResultCapture().sectionStarted( m_info, m_assertions ) ) { m_timer.start(); @@ -30,7 +37,7 @@ namespace Catch { } // This indicates whether the section should be executed or not - Section::operator bool() { + Section::operator bool() const { return m_sectionIncluded; } diff --git a/include/internal/catch_section_info.h b/include/internal/catch_section_info.h index 6bcc72a9..93f3840e 100644 --- a/include/internal/catch_section_info.h +++ b/include/internal/catch_section_info.h @@ -13,13 +13,10 @@ namespace Catch { struct SectionInfo { - SectionInfo( std::string const& _name, - std::string const& _description, - SourceLineInfo const& _lineInfo ) - : name( _name ), - description( _description ), - lineInfo( _lineInfo ) - {} + SectionInfo + ( SourceLineInfo const& _lineInfo, + std::string const& _name, + std::string const& _description = std::string() ); std::string name; std::string description; diff --git a/include/internal/catch_suppress_warnings.h b/include/internal/catch_suppress_warnings.h index e5cfdc56..b39a0b32 100644 --- a/include/internal/catch_suppress_warnings.h +++ b/include/internal/catch_suppress_warnings.h @@ -12,6 +12,7 @@ #pragma clang diagnostic ignored "-Wglobal-constructors" #pragma clang diagnostic ignored "-Wvariadic-macros" #pragma clang diagnostic ignored "-Wc99-extensions" +#pragma clang diagnostic ignored "-Wunused-variable" #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wpadded" #pragma clang diagnostic ignored "-Wc++98-compat" diff --git a/projects/SelfTest/TrickyTests.cpp b/projects/SelfTest/TrickyTests.cpp index 61c2e032..a1676570 100644 --- a/projects/SelfTest/TrickyTests.cpp +++ b/projects/SelfTest/TrickyTests.cpp @@ -387,7 +387,7 @@ TEST_CASE( "pointer to class", "[Tricky]" ) #include -TEST_CASE( "null_ptr", "[Tricky]" ) +TEST_CASE( "null_ptr", "[Tricky][c++11]" ) { std::unique_ptr ptr; REQUIRE(ptr.get() == nullptr); diff --git a/projects/XCode/CatchSelfTest/CatchSelfTest.xcodeproj/project.pbxproj b/projects/XCode/CatchSelfTest/CatchSelfTest.xcodeproj/project.pbxproj index 9ad4cda4..31fc5253 100644 --- a/projects/XCode/CatchSelfTest/CatchSelfTest.xcodeproj/project.pbxproj +++ b/projects/XCode/CatchSelfTest/CatchSelfTest.xcodeproj/project.pbxproj @@ -651,9 +651,10 @@ buildSettings = { CLANG_ANALYZER_SECURITY_FLOATLOOPCOUNTER = YES; CLANG_CXX_LANGUAGE_STANDARD = "c++0x"; - CLANG_CXX_LIBRARY = "libc++"; + CLANG_CXX_LIBRARY = "compiler-default"; CLANG_WARN__DUPLICATE_METHOD_MATCH = NO; GCC_VERSION = com.apple.compilers.llvm.clang.1_0; + OTHER_CPLUSPLUSFLAGS = "$(OTHER_CFLAGS)"; PRODUCT_NAME = "$(TARGET_NAME)"; WARNING_CFLAGS = ( "-Weverything", @@ -667,9 +668,10 @@ buildSettings = { CLANG_ANALYZER_SECURITY_FLOATLOOPCOUNTER = YES; CLANG_CXX_LANGUAGE_STANDARD = "c++0x"; - CLANG_CXX_LIBRARY = "libc++"; + CLANG_CXX_LIBRARY = "compiler-default"; CLANG_WARN__DUPLICATE_METHOD_MATCH = NO; GCC_VERSION = com.apple.compilers.llvm.clang.1_0; + OTHER_CPLUSPLUSFLAGS = "$(OTHER_CFLAGS)"; PRODUCT_NAME = "$(TARGET_NAME)"; WARNING_CFLAGS = ( "-Weverything",