Sweep out some extra warnings

Swept:
`-Wpadded` in some places (where it caused extra size, instead of just
saying "hey, we padded struct at the end to align, just as standard says")
`-Wweak-vtables` everywhere (Clang)
`-Wexit-time-destructors` everywhere (Clang)
`-Wmissing-noreturn` everywhere (Clang)

The last three are enabled for Clang compilation going forward.

Also enabled `-Wunreachable-code` for Clang and GCC
This commit is contained in:
Martin Hořeňovský 2017-09-07 16:51:33 +02:00
parent 6105282c4f
commit 9aa96712ae
61 changed files with 319 additions and 182 deletions

View File

@ -85,16 +85,9 @@ CheckFileList(TEST_SOURCES ${SELF_TEST_DIR})
set(SURROGATE_SOURCES
${SELF_TEST_DIR}/SurrogateCpps/catch_console_colour.cpp
${SELF_TEST_DIR}/SurrogateCpps/catch_debugger.cpp
${SELF_TEST_DIR}/SurrogateCpps/catch_interfaces_capture.cpp
${SELF_TEST_DIR}/SurrogateCpps/catch_interfaces_config.cpp
${SELF_TEST_DIR}/SurrogateCpps/catch_interfaces_exception.cpp
${SELF_TEST_DIR}/SurrogateCpps/catch_interfaces_registry_hub.cpp
${SELF_TEST_DIR}/SurrogateCpps/catch_interfaces_reporter.cpp
${SELF_TEST_DIR}/SurrogateCpps/catch_interfaces_runner.cpp
${SELF_TEST_DIR}/SurrogateCpps/catch_interfaces_testcase.cpp
${SELF_TEST_DIR}/SurrogateCpps/catch_option.cpp
${SELF_TEST_DIR}/SurrogateCpps/catch_stream.cpp
${SELF_TEST_DIR}/SurrogateCpps/catch_streambuf.cpp
${SELF_TEST_DIR}/SurrogateCpps/catch_test_case_tracker.cpp
${SELF_TEST_DIR}/SurrogateCpps/catch_test_spec.cpp
${SELF_TEST_DIR}/SurrogateCpps/catch_xmlwriter.cpp
@ -162,7 +155,7 @@ set(INTERNAL_HEADERS
${HEADER_DIR}/internal/catch_random_number_generator.h
${HEADER_DIR}/internal/catch_reenable_warnings.h
${HEADER_DIR}/internal/catch_reporter_registrars.hpp
${HEADER_DIR}/internal/catch_reporter_registry.hpp
${HEADER_DIR}/internal/catch_reporter_registry.h
${HEADER_DIR}/internal/catch_result_type.h
${HEADER_DIR}/internal/catch_run_context.h
${HEADER_DIR}/internal/catch_benchmark.h
@ -210,6 +203,12 @@ set(IMPL_SOURCES
${HEADER_DIR}/internal/catch_errno_guard.cpp
${HEADER_DIR}/internal/catch_exception_translator_registry.cpp
${HEADER_DIR}/internal/catch_fatal_condition.cpp
${HEADER_DIR}/internal/catch_interfaces_capture.cpp
${HEADER_DIR}/internal/catch_interfaces_config.cpp
${HEADER_DIR}/internal/catch_interfaces_exception.cpp
${HEADER_DIR}/internal/catch_interfaces_registry_hub.cpp
${HEADER_DIR}/internal/catch_interfaces_runner.cpp
${HEADER_DIR}/internal/catch_interfaces_testcase.cpp
${HEADER_DIR}/internal/catch_list.cpp
${HEADER_DIR}/internal/catch_leak_detector.cpp
${HEADER_DIR}/internal/catch_matchers.cpp
@ -218,6 +217,7 @@ set(IMPL_SOURCES
${HEADER_DIR}/internal/catch_registry_hub.cpp
${HEADER_DIR}/internal/catch_interfaces_reporter.cpp
${HEADER_DIR}/internal/catch_random_number_generator.cpp
${HEADER_DIR}/internal/catch_reporter_registry.cpp
${HEADER_DIR}/internal/catch_result_type.cpp
${HEADER_DIR}/internal/catch_run_context.cpp
${HEADER_DIR}/internal/catch_section.cpp
@ -225,6 +225,7 @@ set(IMPL_SOURCES
${HEADER_DIR}/internal/catch_session.cpp
${HEADER_DIR}/internal/catch_startup_exception_registry.cpp
${HEADER_DIR}/internal/catch_stream.cpp
${HEADER_DIR}/internal/catch_streambuf.cpp
${HEADER_DIR}/internal/catch_stringref.cpp
${HEADER_DIR}/internal/catch_string_manip.cpp
${HEADER_DIR}/internal/catch_tag_alias.cpp
@ -298,8 +299,13 @@ if (NOT NO_SELFTEST)
# Add desired warnings
if ( CMAKE_CXX_COMPILER_ID MATCHES "Clang|AppleClang|GNU" )
target_compile_options( SelfTest PRIVATE -Wall -Wextra )
target_compile_options( Benchmark PRIVATE -Wall -Wextra )
target_compile_options( SelfTest PRIVATE -Wall -Wextra -Wunreachable-code )
target_compile_options( Benchmark PRIVATE -Wall -Wextra -Wunreachable-code )
endif()
# Clang specific warning go here
if ( CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
# Actually keep these
target_compile_options( SelfTest PRIVATE -Wweak-vtables -Wexit-time-destructors -Wglobal-constructors -Wmissing-noreturn )
endif()
if ( CMAKE_CXX_COMPILER_ID MATCHES "MSVC" )
target_compile_options( SelfTest PRIVATE /W4 /w44265 /WX )

View File

@ -10,8 +10,8 @@
namespace Catch {
AssertionResultData::AssertionResultData(ResultWas::OfType _resultType, LazyExpression const & _lazyExpression):
resultType(_resultType),
lazyExpression(_lazyExpression) {}
lazyExpression(_lazyExpression),
resultType(_resultType) {}
std::string AssertionResultData::reconstructExpression() const {

View File

@ -23,13 +23,12 @@ namespace Catch {
AssertionResultData( ResultWas::OfType _resultType, LazyExpression const& _lazyExpression );
ResultWas::OfType resultType;
std::string message;
mutable std::string reconstructedExpression;
LazyExpression lazyExpression;
ResultWas::OfType resultType;
std::string reconstructExpression() const;
mutable std::string reconstructedExpression;
};
class AssertionResult {

View File

@ -16,9 +16,18 @@
#endif
#define CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH CATCH_CONFIG_CONSOLE_WIDTH-1
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wweak-vtables"
#pragma clang diagnostic ignored "-Wexit-time-destructors"
#pragma clang diagnostic ignored "-Wshadow"
#endif
#include "../external/clara.hpp"
#ifdef __clang__
#pragma clang diagnostic pop
#endif
// Restore Clara's value for console width, if present
#ifdef CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH

View File

@ -46,4 +46,7 @@ namespace Catch {
return std::string();
}
NonCopyable::NonCopyable() = default;
NonCopyable::~NonCopyable() = default;
}

View File

@ -36,8 +36,8 @@ namespace Catch {
NonCopyable& operator = ( NonCopyable && ) = delete;
protected:
NonCopyable() = default;
virtual ~NonCopyable() = default;
NonCopyable();
virtual ~NonCopyable();
};
struct SourceLineInfo {

View File

@ -35,11 +35,11 @@
#ifdef __clang__
# define CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS \
# define CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
_Pragma( "clang diagnostic push" ) \
_Pragma( "clang diagnostic ignored \"-Wexit-time-destructors\"" )
# define CATCH_INTERNAL_UNSUPPRESS_ETD_WARNINGS \
_Pragma( "clang diagnostic ignored \"-Wexit-time-destructors\"" ) \
_Pragma( "clang diagnostic ignored \"-Wglobal-constructors\"")
# define CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS \
_Pragma( "clang diagnostic pop" )
# define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \
@ -111,9 +111,9 @@
# define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS
# define CATCH_INTERNAL_UNSUPPRESS_PARENTHESES_WARNINGS
#endif
#if !defined(CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS)
# define CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS
# define CATCH_INTERNAL_UNSUPPRESS_ETD_WARNINGS
#if !defined(CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS)
# define CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS
# define CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS
#endif

View File

@ -62,7 +62,6 @@ namespace Catch {
class Config : public IConfig {
virtual void dummy();
public:
Config() = default;

View File

@ -6,6 +6,13 @@
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#if defined(__clang__)
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wexit-time-destructors"
#endif
#include "catch_console_colour.h"
#include "catch_enforce.h"
#include "catch_errno_guard.h"
@ -202,3 +209,8 @@ namespace Catch {
}
} // end namespace Catch
#if defined(__clang__)
# pragma clang diagnostic pop
#endif

View File

@ -24,6 +24,8 @@ namespace Catch {
return m_config;
}
virtual ~Context() override;
public: // IMutableContext
virtual void setResultCapture( IResultCapture* resultCapture ) override {
m_resultCapture = resultCapture;
@ -59,4 +61,7 @@ namespace Catch {
delete currentContext;
currentContext = nullptr;
}
IContext::~IContext() = default;
IMutableContext::~IMutableContext() = default;
Context::~Context() = default;
}

View File

@ -20,7 +20,7 @@ namespace Catch {
struct IContext
{
virtual ~IContext() = default;
virtual ~IContext();
virtual IResultCapture* getResultCapture() = 0;
virtual IRunner* getRunner() = 0;
@ -29,7 +29,7 @@ namespace Catch {
struct IMutableContext : IContext
{
virtual ~IMutableContext() = default;
virtual ~IMutableContext();
virtual void setResultCapture( IResultCapture* resultCapture ) = 0;
virtual void setRunner( IRunner* runner ) = 0;
virtual void setConfig( IConfigPtr const& config ) = 0;

View File

@ -11,6 +11,8 @@
namespace Catch {
ITransientExpression::~ITransientExpression() = default;
void formatReconstructedExpression( std::ostream &os, std::string const& lhs, StringRef op, std::string const& rhs ) {
if( lhs.size() + rhs.size() < 40 &&
lhs.find('\n') == std::string::npos &&

View File

@ -30,7 +30,7 @@ namespace Catch {
// We don't actually need a virtual destructore, but many static analysers
// complain if it's not here :-(
virtual ~ITransientExpression() = default;
virtual ~ITransientExpression();
};
void formatReconstructedExpression( std::ostream &os, std::string const& lhs, StringRef op, std::string const& rhs );
@ -79,24 +79,24 @@ namespace Catch {
template<typename LhsT, typename RhsT>
auto compareEqual( LhsT const& lhs, RhsT&& rhs ) -> bool { return lhs == rhs; };
template<typename T>
auto compareEqual( T* const& lhs, int rhs ) -> bool { return lhs == reinterpret_cast<void const*>( rhs ); };
auto compareEqual( T* const& lhs, int rhs ) -> bool { return lhs == reinterpret_cast<void const*>( rhs ); }
template<typename T>
auto compareEqual( T* const& lhs, long rhs ) -> bool { return lhs == reinterpret_cast<void const*>( rhs ); };
auto compareEqual( T* const& lhs, long rhs ) -> bool { return lhs == reinterpret_cast<void const*>( rhs ); }
template<typename T>
auto compareEqual( int lhs, T* const& rhs ) -> bool { return reinterpret_cast<void const*>( lhs ) == rhs; };
auto compareEqual( int lhs, T* const& rhs ) -> bool { return reinterpret_cast<void const*>( lhs ) == rhs; }
template<typename T>
auto compareEqual( long lhs, T* const& rhs ) -> bool { return reinterpret_cast<void const*>( lhs ) == rhs; };
auto compareEqual( long lhs, T* const& rhs ) -> bool { return reinterpret_cast<void const*>( lhs ) == rhs; }
template<typename LhsT, typename RhsT>
auto compareNotEqual( LhsT const& lhs, RhsT&& rhs ) -> bool { return lhs != rhs; };
template<typename T>
auto compareNotEqual( T* const& lhs, int rhs ) -> bool { return lhs != reinterpret_cast<void const*>( rhs ); };
auto compareNotEqual( T* const& lhs, int rhs ) -> bool { return lhs != reinterpret_cast<void const*>( rhs ); }
template<typename T>
auto compareNotEqual( T* const& lhs, long rhs ) -> bool { return lhs != reinterpret_cast<void const*>( rhs ); };
auto compareNotEqual( T* const& lhs, long rhs ) -> bool { return lhs != reinterpret_cast<void const*>( rhs ); }
template<typename T>
auto compareNotEqual( int lhs, T* const& rhs ) -> bool { return reinterpret_cast<void const*>( lhs ) != rhs; };
auto compareNotEqual( int lhs, T* const& rhs ) -> bool { return reinterpret_cast<void const*>( lhs ) != rhs; }
template<typename T>
auto compareNotEqual( long lhs, T* const& rhs ) -> bool { return reinterpret_cast<void const*>( lhs ) != rhs; };
auto compareNotEqual( long lhs, T* const& rhs ) -> bool { return reinterpret_cast<void const*>( lhs ) != rhs; }
template<typename LhsT>
@ -162,8 +162,4 @@ namespace Catch {
} // end namespace Catch
#ifdef _MSC_VER
#pragma warning(pop)
#endif
#endif // TWOBLUECUBES_CATCH_DECOMPOSER_H_INCLUDED

View File

@ -35,7 +35,7 @@ namespace Catch {
// There is no 1-1 mapping between signals and windows exceptions.
// Windows can easily distinguish between SO and SigSegV,
// but SigInt, SigTerm, etc are handled differently.
SignalDefs signalDefs[] = {
static SignalDefs signalDefs[] = {
{ EXCEPTION_ILLEGAL_INSTRUCTION, "SIGILL - Illegal instruction signal" },
{ EXCEPTION_STACK_OVERFLOW, "SIGSEGV - Stack overflow" },
{ EXCEPTION_ACCESS_VIOLATION, "SIGSEGV - Segmentation violation signal" },
@ -107,7 +107,7 @@ namespace Catch {
int id;
const char* name;
};
SignalDefs signalDefs[] = {
static SignalDefs signalDefs[] = {
{ SIGINT, "SIGINT - Terminal interrupt signal" },
{ SIGILL, "SIGILL - Illegal instruction signal" },
{ SIGFPE, "SIGFPE - Floating point error signal" },

View File

@ -8,39 +8,22 @@
#ifndef TWOBLUECUBES_CATCH_IMPL_HPP_INCLUDED
#define TWOBLUECUBES_CATCH_IMPL_HPP_INCLUDED
// Collect all the implementation files together here
// These are the equivalent of what would usually be cpp files
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wweak-vtables"
#endif
#include "internal/catch_leak_detector.h"
// Keep these here for external reporters
#include "catch_test_spec.h"
#include "catch_test_case_tracker.h"
#include "catch_leak_detector.h"
// Cpp files will be included in the single-header file here
// ~*~* CATCH_CPP_STITCH_PLACE *~*~
namespace Catch {
LeakDetector leakDetector;
// These are all here to avoid warnings about not having any out of line
// virtual methods
IResultCapture::~IResultCapture() {}
ITestInvoker::~ITestInvoker() {}
ITestCaseRegistry::~ITestCaseRegistry() {}
IRegistryHub::~IRegistryHub() {}
IMutableRegistryHub::~IMutableRegistryHub() {}
IExceptionTranslator::~IExceptionTranslator() {}
IExceptionTranslatorRegistry::~IExceptionTranslatorRegistry() {}
IRunner::~IRunner() {}
IConfig::~IConfig() {}
void Config::dummy() {}
}
#ifdef __clang__

View File

@ -0,0 +1,5 @@
#include "catch_interfaces_capture.h"
namespace Catch {
IResultCapture::~IResultCapture() = default;
}

View File

@ -0,0 +1,5 @@
#include "internal/catch_interfaces_config.h"
namespace Catch {
IConfig::~IConfig() = default;
}

View File

@ -0,0 +1,6 @@
#include "internal/catch_interfaces_exception.h"
namespace Catch {
IExceptionTranslator::~IExceptionTranslator() = default;
IExceptionTranslatorRegistry::~IExceptionTranslatorRegistry() = default;
}

View File

@ -0,0 +1,6 @@
#include "internal/catch_interfaces_registry_hub.h"
namespace Catch {
IRegistryHub::~IRegistryHub() = default;
IMutableRegistryHub::~IMutableRegistryHub() = default;
}

View File

@ -50,6 +50,8 @@ namespace Catch {
}
}
AssertionStats::~AssertionStats() = default;
SectionStats::SectionStats( SectionInfo const& _sectionInfo,
Counts const& _assertions,
double _durationInSeconds,
@ -60,6 +62,8 @@ namespace Catch {
missingAssertions( _missingAssertions )
{}
SectionStats::~SectionStats() = default;
TestCaseStats::TestCaseStats( TestCaseInfo const& _testInfo,
Totals const& _totals,
@ -73,6 +77,8 @@ namespace Catch {
aborting( _aborting )
{}
TestCaseStats::~TestCaseStats() = default;
TestGroupStats::TestGroupStats( GroupInfo const& _groupInfo,
Totals const& _totals,
@ -87,6 +93,8 @@ namespace Catch {
aborting( false )
{}
TestGroupStats::~TestGroupStats() = default;
TestRunStats::TestRunStats( TestRunInfo const& _runInfo,
Totals const& _totals,
bool _aborting )
@ -95,9 +103,14 @@ namespace Catch {
aborting( _aborting )
{}
TestRunStats::~TestRunStats() = default;
bool IStreamingReporter::isMulti() const { return false; }
IReporterFactory::~IReporterFactory() = default;
IReporterRegistry::~IReporterRegistry() = default;
void addReporter( IStreamingReporterPtr& existingReporter, IStreamingReporterPtr&& additionalReporter ) {
if( !existingReporter ) {

View File

@ -80,7 +80,7 @@ namespace Catch {
AssertionStats( AssertionStats && ) = default;
AssertionStats& operator = ( AssertionStats const& ) = default;
AssertionStats& operator = ( AssertionStats && ) = default;
virtual ~AssertionStats() = default;
virtual ~AssertionStats();
AssertionResult assertionResult;
std::vector<MessageInfo> infoMessages;
@ -96,7 +96,7 @@ namespace Catch {
SectionStats( SectionStats && ) = default;
SectionStats& operator = ( SectionStats const& ) = default;
SectionStats& operator = ( SectionStats && ) = default;
virtual ~SectionStats() = default;
virtual ~SectionStats();
SectionInfo sectionInfo;
Counts assertions;
@ -115,7 +115,7 @@ namespace Catch {
TestCaseStats( TestCaseStats && ) = default;
TestCaseStats& operator = ( TestCaseStats const& ) = default;
TestCaseStats& operator = ( TestCaseStats && ) = default;
virtual ~TestCaseStats() = default;
virtual ~TestCaseStats();
TestCaseInfo testInfo;
Totals totals;
@ -134,7 +134,7 @@ namespace Catch {
TestGroupStats( TestGroupStats && ) = default;
TestGroupStats& operator = ( TestGroupStats const& ) = default;
TestGroupStats& operator = ( TestGroupStats && ) = default;
virtual ~TestGroupStats() = default;
virtual ~TestGroupStats();
GroupInfo groupInfo;
Totals totals;
@ -150,7 +150,7 @@ namespace Catch {
TestRunStats( TestRunStats && ) = default;
TestRunStats& operator = ( TestRunStats const& ) = default;
TestRunStats& operator = ( TestRunStats && ) = default;
virtual ~TestRunStats() = default;
virtual ~TestRunStats();
TestRunInfo runInfo;
Totals totals;
@ -206,7 +206,7 @@ namespace Catch {
using IStreamingReporterPtr = std::unique_ptr<IStreamingReporter>;
struct IReporterFactory {
virtual ~IReporterFactory() = default;
virtual ~IReporterFactory();
virtual IStreamingReporterPtr create( ReporterConfig const& config ) const = 0;
virtual std::string getDescription() const = 0;
};
@ -216,7 +216,7 @@ namespace Catch {
using FactoryMap = std::map<std::string, IReporterFactoryPtr>;
using Listeners = std::vector<IReporterFactoryPtr>;
virtual ~IReporterRegistry() = default;
virtual ~IReporterRegistry();
virtual IStreamingReporterPtr create( std::string const& name, IConfigPtr const& config ) const = 0;
virtual FactoryMap const& getFactories() const = 0;
virtual Listeners const& getListeners() const = 0;

View File

@ -0,0 +1,5 @@
#include "internal/catch_interfaces_runner.h"
namespace Catch {
IRunner::~IRunner() = default;
}

View File

@ -0,0 +1,6 @@
#include "internal/catch_interfaces_testcase.h"
namespace Catch {
ITestInvoker::~ITestInvoker() = default;
ITestCaseRegistry::~ITestCaseRegistry() = default;
}

View File

@ -17,6 +17,8 @@ namespace Matchers {
return m_cachedToString;
}
MatcherUntypedBase::~MatcherUntypedBase() = default;
} // namespace Impl
} // namespace Matchers

View File

@ -29,7 +29,7 @@ namespace Matchers {
std::string toString() const;
protected:
virtual ~MatcherUntypedBase() = default;
virtual ~MatcherUntypedBase();
virtual std::string describe() const = 0;
mutable std::string m_cachedToString;
};

View File

@ -21,9 +21,9 @@ namespace Catch {
ResultWas::OfType _type );
std::string macroName;
std::string message;
SourceLineInfo lineInfo;
ResultWas::OfType type;
std::string message;
unsigned int sequence;
bool operator == ( MessageInfo const& other ) const;

View File

@ -10,7 +10,7 @@
#include "catch_context.h"
#include "catch_test_case_registry_impl.h"
#include "catch_reporter_registry.hpp"
#include "catch_reporter_registry.h"
#include "catch_exception_translator_registry.h"
#include "catch_tag_alias_registry.h"
#include "catch_startup_exception_registry.h"
@ -23,8 +23,7 @@ namespace Catch {
private NonCopyable {
public: // IRegistryHub
RegistryHub() {
}
RegistryHub() = default;
IReporterRegistry const& getReporterRegistry() const override {
return m_reporterRegistry;
}

View File

@ -58,11 +58,14 @@ namespace Catch {
#if !defined(CATCH_CONFIG_DISABLE)
#define CATCH_REGISTER_REPORTER( name, reporterType ) \
namespace{ Catch::ReporterRegistrar<reporterType> catch_internal_RegistrarFor##reporterType( name ); }
CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
namespace{ Catch::ReporterRegistrar<reporterType> catch_internal_RegistrarFor##reporterType( name ); } \
CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS
#define CATCH_REGISTER_LISTENER( listenerType ) \
namespace{ Catch::ListenerRegistrar<listenerType> catch_internal_RegistrarFor##listenerType; }
CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
namespace{ Catch::ListenerRegistrar<listenerType> catch_internal_RegistrarFor##listenerType; } \
CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS
#else // CATCH_CONFIG_DISABLE
#define CATCH_REGISTER_REPORTER(name, reporterType)

View File

@ -0,0 +1,34 @@
/*
* Created by Martin on 31/08/2017.
*
* Distributed under the Boost Software License, Version 1.0. (See accompanying
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#include "catch_reporter_registry.h"
namespace Catch {
ReporterRegistry::~ReporterRegistry() = default;
IStreamingReporterPtr ReporterRegistry::create( std::string const& name, IConfigPtr const& config ) const {
auto it = m_factories.find( name );
if( it == m_factories.end() )
return nullptr;
return it->second->create( ReporterConfig( config ) );
}
void ReporterRegistry::registerReporter( std::string const& name, IReporterFactoryPtr const& factory ) {
m_factories.emplace(name, factory);
}
void ReporterRegistry::registerListener( IReporterFactoryPtr const& factory ) {
m_listeners.push_back( factory );
}
IReporterRegistry::FactoryMap const& ReporterRegistry::getFactories() const {
return m_factories;
}
IReporterRegistry::Listeners const& ReporterRegistry::getListeners() const {
return m_listeners;
}
}

View File

@ -0,0 +1,37 @@
/*
* Created by Phil on 29/10/2010.
* Copyright 2010 Two Blue Cubes Ltd. All rights reserved.
*
* Distributed under the Boost Software License, Version 1.0. (See accompanying
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef TWOBLUECUBES_CATCH_REPORTER_REGISTRY_H_INCLUDED
#define TWOBLUECUBES_CATCH_REPORTER_REGISTRY_H_INCLUDED
#include "catch_interfaces_reporter.h"
#include <map>
namespace Catch {
class ReporterRegistry : public IReporterRegistry {
public:
~ReporterRegistry() override;
IStreamingReporterPtr create( std::string const& name, IConfigPtr const& config ) const override;
void registerReporter( std::string const& name, IReporterFactoryPtr const& factory );
void registerListener( IReporterFactoryPtr const& factory );
FactoryMap const& getFactories() const override;
Listeners const& getListeners() const override;
private:
FactoryMap m_factories;
Listeners m_listeners;
};
}
#endif // TWOBLUECUBES_CATCH_REPORTER_REGISTRY_H_INCLUDED

View File

@ -1,50 +0,0 @@
/*
* Created by Phil on 29/10/2010.
* Copyright 2010 Two Blue Cubes Ltd. All rights reserved.
*
* Distributed under the Boost Software License, Version 1.0. (See accompanying
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef TWOBLUECUBES_CATCH_REPORTER_REGISTRY_HPP_INCLUDED
#define TWOBLUECUBES_CATCH_REPORTER_REGISTRY_HPP_INCLUDED
#include "catch_interfaces_reporter.h"
#include <map>
namespace Catch {
class ReporterRegistry : public IReporterRegistry {
public:
~ReporterRegistry() override {}
IStreamingReporterPtr create( std::string const& name, IConfigPtr const& config ) const override {
auto it = m_factories.find( name );
if( it == m_factories.end() )
return nullptr;
return it->second->create( ReporterConfig( config ) );
}
void registerReporter( std::string const& name, IReporterFactoryPtr const& factory ) {
m_factories.emplace(name, factory);
}
void registerListener( IReporterFactoryPtr const& factory ) {
m_listeners.push_back( factory );
}
FactoryMap const& getFactories() const override {
return m_factories;
}
Listeners const& getListeners() const override {
return m_listeners;
}
private:
FactoryMap m_factories;
Listeners m_listeners;
};
}
#endif // TWOBLUECUBES_CATCH_REPORTER_REGISTRY_HPP_INCLUDED

View File

@ -57,6 +57,8 @@ namespace Catch {
///////////////////////////////////////////////////////////////////////////
Catch::IStream::~IStream() = default;
FileStream::FileStream( std::string const& filename ) {
m_ofs.open( filename.c_str() );
CATCH_ENFORCE( !m_ofs.fail(), "Unable to open file: '" << filename << "'" );

View File

@ -24,7 +24,7 @@ namespace Catch {
struct IStream {
virtual ~IStream() = default;
virtual ~IStream();
virtual std::ostream& stream() const = 0;
};

View File

@ -0,0 +1,12 @@
/*
* Created by Martin on 31/08/2017.
*
* Distributed under the Boost Software License, Version 1.0. (See accompanying
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#include "catch_streambuf.h"
namespace Catch {
StreamBufBase::~StreamBufBase() = default;
}

View File

@ -8,15 +8,13 @@
#ifndef TWOBLUECUBES_CATCH_STREAMBUF_H_INCLUDED
#define TWOBLUECUBES_CATCH_STREAMBUF_H_INCLUDED
#include "catch_compiler_capabilities.h"
#include <streambuf>
namespace Catch {
class StreamBufBase : public std::streambuf {
public:
virtual ~StreamBufBase() = default;
virtual ~StreamBufBase();
};
}

View File

@ -5,12 +5,20 @@
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#if defined(__clang__)
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wexit-time-destructors"
#endif
#include "catch_stringref.h"
#include <ostream>
#include <cassert>
#include <cstring>
namespace Catch {
auto getEmptyStringRef() -> StringRef {
@ -160,3 +168,7 @@ namespace Catch {
}
} // namespace Catch
#if defined(__clang__)
# pragma clang diagnostic pop
#endif

View File

@ -14,7 +14,10 @@
#include <stdexcept>
#include <memory>
CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS
#if defined(__clang__)
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wexit-time-destructors"
#endif
namespace Catch {
namespace TestCaseTracking {
@ -25,6 +28,8 @@ namespace TestCaseTracking {
{}
ITracker::~ITracker() = default;
TrackerContext& TrackerContext::instance() {
static TrackerContext s_instance;
@ -276,4 +281,6 @@ using TestCaseTracking::IndexTracker;
} // namespace Catch
CATCH_INTERNAL_UNSUPPRESS_ETD_WARNINGS
#if defined(__clang__)
# pragma clang diagnostic pop
#endif

View File

@ -15,8 +15,6 @@
#include <vector>
#include <memory>
CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS
namespace Catch {
namespace TestCaseTracking {
@ -32,7 +30,7 @@ namespace TestCaseTracking {
using ITrackerPtr = std::shared_ptr<ITracker>;
struct ITracker {
virtual ~ITracker() = default;
virtual ~ITracker();
// static queries
virtual NameAndLocation const& nameAndLocation() const = 0;
@ -182,6 +180,4 @@ using TestCaseTracking::IndexTracker;
} // namespace Catch
CATCH_INTERNAL_UNSUPPRESS_ETD_WARNINGS
#endif // TWOBLUECUBES_CATCH_TEST_CASE_TRACKER_HPP_INCLUDED

View File

@ -32,4 +32,6 @@ namespace Catch {
getMutableRegistryHub().registerStartupException();
}
}
AutoReg::~AutoReg() = default;
}

View File

@ -42,7 +42,7 @@ struct NameAndTags {
struct AutoReg : NonCopyable {
AutoReg( ITestInvoker* invoker, SourceLineInfo const& lineInfo, StringRef classOrMethod, NameAndTags const& nameAndTags ) noexcept;
~AutoReg() = default;
~AutoReg();
};
} // end namespace Catch
@ -63,38 +63,38 @@ struct AutoReg : NonCopyable {
///////////////////////////////////////////////////////////////////////////////
#define INTERNAL_CATCH_TESTCASE2( TestName, ... ) \
static void TestName(); \
CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS \
CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( Catch::makeTestInvoker( &TestName ), CATCH_INTERNAL_LINEINFO, "", Catch::NameAndTags{ __VA_ARGS__ } ); } /* NOLINT */ \
CATCH_INTERNAL_UNSUPPRESS_ETD_WARNINGS \
CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS \
static void TestName()
#define INTERNAL_CATCH_TESTCASE( ... ) \
INTERNAL_CATCH_TESTCASE2( INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ), __VA_ARGS__ )
///////////////////////////////////////////////////////////////////////////////
#define INTERNAL_CATCH_METHOD_AS_TEST_CASE( QualifiedMethod, ... ) \
CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS \
CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( Catch::makeTestInvoker( &QualifiedMethod ), CATCH_INTERNAL_LINEINFO, "&" #QualifiedMethod, Catch::NameAndTags{ __VA_ARGS__ } ); } /* NOLINT */ \
CATCH_INTERNAL_UNSUPPRESS_ETD_WARNINGS
CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS
///////////////////////////////////////////////////////////////////////////////
#define INTERNAL_CATCH_TEST_CASE_METHOD2( TestName, ClassName, ... )\
CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS \
CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
namespace{ \
struct TestName : ClassName{ \
void test(); \
}; \
Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar ) ( Catch::makeTestInvoker( &TestName::test ), CATCH_INTERNAL_LINEINFO, #ClassName, Catch::NameAndTags{ __VA_ARGS__ } ); /* NOLINT */ \
} \
CATCH_INTERNAL_UNSUPPRESS_ETD_WARNINGS \
CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS \
void TestName::test()
#define INTERNAL_CATCH_TEST_CASE_METHOD( ClassName, ... ) \
INTERNAL_CATCH_TEST_CASE_METHOD2( INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ), ClassName, __VA_ARGS__ )
///////////////////////////////////////////////////////////////////////////////
#define INTERNAL_CATCH_REGISTER_TESTCASE( Function, ... ) \
CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS \
CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( Catch::makeTestInvoker( Function ), CATCH_INTERNAL_LINEINFO, "", Catch::NameAndTags{ __VA_ARGS__ } ); /* NOLINT */ \
CATCH_INTERNAL_UNSUPPRESS_ETD_WARNINGS
CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS
#endif // TWOBLUECUBES_CATCH_TEST_REGISTRY_HPP_INCLUDED

View File

@ -15,6 +15,11 @@
namespace Catch {
TestSpec::Pattern::~Pattern() = default;
TestSpec::NamePattern::~NamePattern() = default;
TestSpec::TagPattern::~TagPattern() = default;
TestSpec::ExcludedPattern::~ExcludedPattern() = default;
TestSpec::NamePattern::NamePattern( std::string const& name )
: m_wildcardPattern( toLower( name ), CaseSensitive::No )
{}

View File

@ -24,7 +24,7 @@ namespace Catch {
class TestSpec {
struct Pattern {
virtual ~Pattern() = default;
virtual ~Pattern();
virtual bool matches( TestCaseInfo const& testCase ) const = 0;
};
using PatternPtr = std::shared_ptr<Pattern>;
@ -32,7 +32,7 @@ namespace Catch {
class NamePattern : public Pattern {
public:
NamePattern( std::string const& name );
virtual ~NamePattern() = default;
virtual ~NamePattern();
virtual bool matches( TestCaseInfo const& testCase ) const override;
private:
WildcardPattern m_wildcardPattern;
@ -41,7 +41,7 @@ namespace Catch {
class TagPattern : public Pattern {
public:
TagPattern( std::string const& tag );
virtual ~TagPattern() = default;
virtual ~TagPattern();
virtual bool matches( TestCaseInfo const& testCase ) const override;
private:
std::string m_tag;
@ -50,7 +50,7 @@ namespace Catch {
class ExcludedPattern : public Pattern {
public:
ExcludedPattern( PatternPtr const& underlyingPattern );
virtual ~ExcludedPattern() = default;
virtual ~ExcludedPattern();
virtual bool matches( TestCaseInfo const& testCase ) const override;
private:
PatternPtr m_underlyingPattern;

View File

@ -6,6 +6,13 @@
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#if defined(__clang__)
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wexit-time-destructors"
# pragma clang diagnostic ignored "-Wglobal-constructors"
#endif
#include "catch_tostring.h"
#include "catch_interfaces_config.h"
#include "catch_context.h"
@ -211,3 +218,8 @@ std::string StringMaker<double>::convert(double value) {
} // end namespace Catch
#if defined(__clang__)
# pragma clang diagnostic pop
#endif

View File

@ -22,9 +22,10 @@
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable:4180) // qualifier applied to function type has no meaning
#pragma warning(disable:4180) // We attempt to stream a function (address) by const&, which MSVC complains about but is harmless
#endif
// We need a dummy global operator<< so we can bring it into Catch namespace later
struct Catch_global_namespace_dummy;
std::ostream& operator<<(std::ostream&, Catch_global_namespace_dummy);

View File

@ -64,13 +64,13 @@ namespace Catch {
public:
AssertionPrinter& operator= ( AssertionPrinter const& ) = delete;
AssertionPrinter( AssertionPrinter const& ) = delete;
AssertionPrinter( std::ostream& _stream, AssertionStats const& _stats, size_t counter )
AssertionPrinter( std::ostream& _stream, AssertionStats const& _stats, size_t _counter )
: stream( _stream )
, result( _stats.assertionResult )
, messages( _stats.infoMessages )
, itMessage( _stats.infoMessages.begin() )
, printInfoMessages( true )
, counter(counter)
, counter(_counter)
{}
void print() {

View File

@ -1003,6 +1003,6 @@ with expansion:
"{?}" == "1"
===============================================================================
test cases: 177 | 126 passed | 47 failed | 4 failed as expected
test cases: 176 | 125 passed | 47 failed | 4 failed as expected
assertions: 878 | 761 passed | 96 failed | 21 failed as expected

View File

@ -7434,6 +7434,6 @@ MiscTests.cpp:<line number>:
PASSED:
===============================================================================
test cases: 177 | 124 passed | 49 failed | 4 failed as expected
test cases: 176 | 123 passed | 49 failed | 4 failed as expected
assertions: 877 | 757 passed | 99 failed | 21 failed as expected

View File

@ -6946,9 +6946,6 @@ Message from section two
</Section>
<OverallResult success="true"/>
</TestCase>
<TestCase name="assertions with commas are allowed" filename="projects/<exe-name>/TrickyTests.cpp" >
<OverallResult success="true"/>
</TestCase>
<TestCase name="atomic if" tags="[0][failing]" filename="projects/<exe-name>/MiscTests.cpp" >
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/MiscTests.cpp" >
<Original>

View File

@ -6,7 +6,9 @@
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifdef __clang__
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wpadded"
# pragma clang diagnostic ignored "-Wdouble-promotion"
#endif
#include "catch.hpp"
@ -161,6 +163,11 @@ TEST_CASE( "Ordering comparison checks that should fail", "[.][failing]" )
CHECK( data.str_hello <= "a" );
}
#ifdef __clang__
# pragma clang diagnostic pop
#endif
// Comparisons with int literals
TEST_CASE( "Comparisons with int literals don't warn when mixing signed/ unsigned" )
{

View File

@ -14,6 +14,10 @@
#ifdef _MSC_VER
#pragma warning(disable:4702) // Unreachable code -- MSVC 19 (VS 2015) sees right through the indirection
#endif
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wweak-vtables"
#endif
namespace
{
@ -219,3 +223,7 @@ TEST_CASE( "#748 - captures with unexpected exceptions", "[.][failing][!throws][
REQUIRE_THROWS( thisThrows() );
}
}
#ifdef __clang__
#pragma clang diagnostic pop
#endif

View File

@ -8,6 +8,12 @@
#include "catch.hpp"
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wweak-vtables"
#pragma clang diagnostic ignored "-Wpadded"
#endif
#ifndef CATCH_CONFIG_DISABLE_MATCHERS
inline const char* testStringForMatching()
@ -166,16 +172,18 @@ TEST_CASE( "Vector matchers that fail", "[matchers][vector][.][failing]" ) {
#include <exception>
struct SpecialException : std::exception {
SpecialException(int i):i(i) {}
SpecialException(int i_):i(i_) {}
int i;
};
void doesNotThrow() {}
[[noreturn]]
void throws(int i) {
throw SpecialException{ i };
}
[[noreturn]]
void throwsAsInt(int i) {
throw i;
}
@ -217,3 +225,7 @@ TEST_CASE("Exception matchers that fail", "[matchers][exceptions][!throws][.fail
}
#endif // CATCH_CONFIG_DISABLE_MATCHERS
#ifdef __clang__
#pragma clang diagnostic pop
#endif

View File

@ -1,3 +0,0 @@
// This file is only here to verify (to the extent possible) the self sufficiency of the header
#include "internal/catch_suppress_warnings.h"
#include "internal/catch_interfaces_capture.h"

View File

@ -1,2 +0,0 @@
#include "internal/catch_suppress_warnings.h"
#include "internal/catch_interfaces_config.h"

View File

@ -1,2 +0,0 @@
#include "internal/catch_suppress_warnings.h"
#include "internal/catch_interfaces_exception.h"

View File

@ -1,3 +0,0 @@
// This file is only here to verify (to the extent possible) the self sufficiency of the header
#include "internal/catch_suppress_warnings.h"
#include "internal/catch_interfaces_registry_hub.h"

View File

@ -1 +0,0 @@
#include "internal/catch_interfaces_runner.h"

View File

@ -1,2 +0,0 @@
#include "internal/catch_suppress_warnings.h"
#include "internal/catch_interfaces_testcase.h"

View File

@ -1,3 +0,0 @@
// This file is only here to verify (to the extent possible) the self sufficiency of the header
#include "internal/catch_suppress_warnings.h"
#include "internal/catch_streambuf.h"

View File

@ -265,4 +265,4 @@ struct AutoTestReg {
REGISTER_TEST_CASE( manuallyRegisteredTestFunction, "ManuallyRegistered" );
}
};
AutoTestReg autoTestReg;
static AutoTestReg autoTestReg;

View File

@ -381,12 +381,9 @@ TEST_CASE( "has printf" ) {
printf( "loose text artifact\n" );
}
TEST_CASE( "assertions with commas are allowed" ) {
}
namespace {
struct constructor_throws {
constructor_throws() {
[[noreturn]] constructor_throws() {
throw 1;
}
};