A load more C++11 tweaks - mostly moving initialisations from constructors to inline

This commit is contained in:
Phil Nash 2017-04-25 18:56:53 +01:00
parent cc8206f4c3
commit e749724a11
23 changed files with 64 additions and 145 deletions

View File

@ -27,12 +27,7 @@ namespace Detail {
m_value( value )
{}
Approx( Approx const& other )
: m_epsilon( other.m_epsilon ),
m_margin( other.m_margin ),
m_scale( other.m_scale ),
m_value( other.m_value )
{}
Approx( Approx const& other ) = default;
static Approx custom() {
return Approx( 0 );

View File

@ -53,11 +53,6 @@ namespace Catch {
struct AssertionResultData
{
AssertionResultData() : decomposedExpression( nullptr )
, resultType( ResultWas::Unknown )
, negated( false )
, parenthesized( false ) {}
void negate( bool parenthesize ) {
negated = !negated;
parenthesized = parenthesize;
@ -82,12 +77,12 @@ namespace Catch {
return reconstructedExpression;
}
mutable DecomposedExpression const* decomposedExpression;
mutable DecomposedExpression const* decomposedExpression = nullptr;
mutable std::string reconstructedExpression;
std::string message;
ResultWas::OfType resultType;
bool negated;
bool parenthesized;
ResultWas::OfType resultType = ResultWas::Unknown;
bool negated = false;
bool parenthesized = false;
};
class AssertionResult {

View File

@ -25,47 +25,26 @@
namespace Catch {
struct ConfigData {
bool listTests = false;
bool listTags = false;
bool listReporters = false;
bool listTestNamesOnly = false;
ConfigData()
: listTests( false ),
listTags( false ),
listReporters( false ),
listTestNamesOnly( false ),
showSuccessfulTests( false ),
shouldDebugBreak( false ),
noThrow( false ),
showHelp( false ),
showInvisibles( false ),
filenamesAsTags( false ),
abortAfter( -1 ),
rngSeed( 0 ),
verbosity( Verbosity::Normal ),
warnings( WarnAbout::Nothing ),
showDurations( ShowDurations::DefaultForReporter ),
runOrder( RunTests::InDeclarationOrder ),
useColour( UseColour::Auto )
{}
bool showSuccessfulTests = false;
bool shouldDebugBreak = false;
bool noThrow = false;
bool showHelp = false;
bool showInvisibles = false;
bool filenamesAsTags = false;
bool listTests;
bool listTags;
bool listReporters;
bool listTestNamesOnly;
int abortAfter = -1;
unsigned int rngSeed = 0;
bool showSuccessfulTests;
bool shouldDebugBreak;
bool noThrow;
bool showHelp;
bool showInvisibles;
bool filenamesAsTags;
int abortAfter;
unsigned int rngSeed;
Verbosity::Level verbosity;
WarnAbout::What warnings;
ShowDurations::OrNot showDurations;
RunTests::InWhatOrder runOrder;
UseColour::YesOrNo useColour;
Verbosity::Level verbosity = Verbosity::Normal;
WarnAbout::What warnings = WarnAbout::Nothing;
ShowDurations::OrNot showDurations = ShowDurations::DefaultForReporter;
RunTests::InWhatOrder runOrder = RunTests::InDeclarationOrder;
UseColour::YesOrNo useColour = UseColour::Auto;
std::string outputFilename;
std::string name;

View File

@ -16,11 +16,7 @@
namespace Catch {
class Context : public IMutableContext {
Context() : m_config( nullptr ), m_runner( nullptr ), m_resultCapture( nullptr ) {}
Context( Context const& );
void operator=( Context const& );
class Context : public IMutableContext, NonCopyable {
public:
virtual ~Context() {
@ -84,8 +80,8 @@ namespace Catch {
private:
Ptr<IConfig const> m_config;
IRunner* m_runner;
IResultCapture* m_resultCapture;
IRunner* m_runner = nullptr;
IResultCapture* m_resultCapture = nullptr;
std::map<std::string, IGeneratorsForTest*> m_generatorsByTestName;
};

View File

@ -25,7 +25,7 @@ class MatchExpression;
template<typename T>
class ExpressionLhs : public DecomposedExpression {
public:
ExpressionLhs( ResultBuilder& rb, T lhs ) : m_rb( rb ), m_lhs( lhs ), m_truthy(false) {}
ExpressionLhs( ResultBuilder& rb, T lhs ) : m_rb( rb ), m_lhs( lhs ) {}
ExpressionLhs& operator = ( const ExpressionLhs& );
@ -98,7 +98,7 @@ private:
private:
ResultBuilder& m_rb;
T m_lhs;
bool m_truthy;
bool m_truthy = false;
};
template<typename LhsT, Internal::Operator Op, typename RhsT>

View File

@ -71,7 +71,6 @@ namespace Catch {
}
struct TagInfo {
TagInfo() : count ( 0 ) {}
void add( std::string const& spelling ) {
++count;
spellings.insert( spelling );
@ -83,7 +82,7 @@ namespace Catch {
return out;
}
std::set<std::string> spellings;
std::size_t count;
std::size_t count = 0;
};
inline std::size_t listTags( Config const& config ) {

View File

@ -20,7 +20,7 @@ namespace Catch {
template<typename T> class ExpressionLhs;
struct CopyableStream {
CopyableStream() {}
CopyableStream() = default;
CopyableStream( CopyableStream const& other ) {
oss << other.oss.str();
}
@ -82,9 +82,9 @@ namespace Catch {
AssertionResultData m_data;
CopyableStream m_stream;
bool m_shouldDebugBreak;
bool m_shouldThrow;
bool m_guardException;
bool m_shouldDebugBreak = false;
bool m_shouldThrow = false;
bool m_guardException = false;
};
} // namespace Catch

View File

@ -28,10 +28,7 @@ namespace Catch {
char const* capturedExpression,
ResultDisposition::Flags resultDisposition,
char const* secondArg )
: m_assertionInfo( macroName, lineInfo, capturedExpressionWithSecondArgument( capturedExpression, secondArg ), resultDisposition ),
m_shouldDebugBreak( false ),
m_shouldThrow( false ),
m_guardException( false )
: m_assertionInfo( macroName, lineInfo, capturedExpressionWithSecondArgument( capturedExpression, secondArg ), resultDisposition )
{}
ResultBuilder::~ResultBuilder() {

View File

@ -62,10 +62,8 @@ namespace Catch {
explicit RunContext( Ptr<IConfig const> const& _config, Ptr<IStreamingReporter> const& reporter )
: m_runInfo( _config->name() ),
m_context( getCurrentMutableContext() ),
m_activeTestCase( nullptr ),
m_config( _config ),
m_reporter( reporter ),
m_shouldReportUnexpected ( true )
m_reporter( reporter )
{
m_context.setRunner( this );
m_context.setConfig( m_config );
@ -350,7 +348,7 @@ namespace Catch {
TestRunInfo m_runInfo;
IMutableContext& m_context;
TestCase const* m_activeTestCase;
TestCase const* m_activeTestCase = nullptr;
ITracker* m_testCaseTracker;
ITracker* m_currentSectionTracker;
AssertionResult m_lastResult;
@ -363,7 +361,7 @@ namespace Catch {
std::vector<SectionEndInfo> m_unfinishedSections;
std::vector<ITracker*> m_activeSections;
TrackerContext m_trackerContext;
bool m_shouldReportUnexpected;
bool m_shouldReportUnexpected = true;
};
IResultCapture& getResultCapture() {

View File

@ -22,7 +22,7 @@ namespace Catch {
~Section();
// This indicates whether the section should be executed or not
operator bool() const;
explicit operator bool() const;
private:
SectionInfo m_info;

View File

@ -16,8 +16,6 @@
# pragma clang diagnostic ignored "-Wunused-variable"
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wpadded"
# pragma clang diagnostic ignored "-Wc++98-compat"
# pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
# pragma clang diagnostic ignored "-Wswitch-enum"
# pragma clang diagnostic ignored "-Wcovered-switch-default"
# endif

View File

@ -91,10 +91,6 @@ namespace Catch {
class TestRegistry : public ITestCaseRegistry {
public:
TestRegistry()
: m_currentSortOrder( RunTests::InDeclarationOrder ),
m_unnamedCount( 0 )
{}
virtual ~TestRegistry();
virtual void registerTest( TestCase const& testCase ) {
@ -123,9 +119,9 @@ namespace Catch {
private:
std::vector<TestCase> m_functions;
mutable RunTests::InWhatOrder m_currentSortOrder;
mutable RunTests::InWhatOrder m_currentSortOrder = RunTests::InDeclarationOrder;
mutable std::vector<TestCase> m_sortedFunctions;
size_t m_unnamedCount;
size_t m_unnamedCount = 0;
std::ios_base::Init m_ostreamInit; // Forces cout/ cerr to be initialised
};

View File

@ -69,8 +69,8 @@ namespace TestCaseTracking {
};
Ptr<ITracker> m_rootTracker;
ITracker* m_currentTracker;
RunState m_runState;
ITracker* m_currentTracker = nullptr;
RunState m_runState = NotStarted;
public:
@ -79,12 +79,6 @@ namespace TestCaseTracking {
return s_instance;
}
TrackerContext()
: m_currentTracker( nullptr ),
m_runState( NotStarted )
{}
ITracker& startRun();
void endRun() {
@ -137,13 +131,12 @@ namespace TestCaseTracking {
TrackerContext& m_ctx;
ITracker* m_parent;
Children m_children;
CycleState m_runState;
CycleState m_runState = NotStarted;
public:
TrackerBase( NameAndLocation const& nameAndLocation, TrackerContext& ctx, ITracker* parent )
: m_nameAndLocation( nameAndLocation ),
m_ctx( ctx ),
m_parent( parent ),
m_runState( NotStarted )
m_parent( parent )
{}
virtual ~TrackerBase();
@ -302,12 +295,11 @@ namespace TestCaseTracking {
class IndexTracker : public TrackerBase {
int m_size;
int m_index;
int m_index = -1;
public:
IndexTracker( NameAndLocation const& nameAndLocation, TrackerContext& ctx, ITracker* parent, int size )
: TrackerBase( nameAndLocation, ctx, parent ),
m_size( size ),
m_index( -1 )
m_size( size )
{}
virtual ~IndexTracker();

View File

@ -13,14 +13,13 @@
namespace Catch {
class Timer {
public:
Timer() : m_microSeconds( 0 ) {}
void start();
unsigned int getElapsedMicroseconds() const;
unsigned int getElapsedMilliseconds() const;
double getElapsedSeconds() const;
private:
uint64_t m_microSeconds;
uint64_t m_microSeconds = 0;
};
} // namespace Catch

View File

@ -13,8 +13,6 @@
namespace Catch {
struct Counts {
Counts() : passed( 0 ), failed( 0 ), failedButOk( 0 ) {}
Counts operator - ( Counts const& other ) const {
Counts diff;
diff.passed = passed - other.passed;
@ -39,9 +37,9 @@ namespace Catch {
return failed == 0;
}
std::size_t passed;
std::size_t failed;
std::size_t failedButOk;
std::size_t passed = 0;
std::size_t failed = 0;
std::size_t failedButOk = 0;
};
struct Totals {

View File

@ -27,7 +27,6 @@ namespace Catch
WildcardPattern( std::string const& pattern, CaseSensitive::Choice caseSensitivity )
: m_caseSensitivity( caseSensitivity ),
m_wildcard( NoWildcard ),
m_pattern( adjustCase( pattern ) )
{
if( startsWith( m_pattern, '*' ) ) {
@ -66,7 +65,7 @@ namespace Catch
return m_caseSensitivity == CaseSensitive::No ? toLower( str ) : str;
}
CaseSensitive::Choice m_caseSensitivity;
WildcardPosition m_wildcard;
WildcardPosition m_wildcard = NoWildcard;
std::string m_pattern;
};
}

View File

@ -112,18 +112,7 @@ namespace Catch {
mutable XmlWriter* m_writer;
};
XmlWriter()
: m_tagIsOpen( false ),
m_needsNewline( false ),
m_os( Catch::cout() )
{
writeDeclaration();
}
XmlWriter( std::ostream& os )
: m_tagIsOpen( false ),
m_needsNewline( false ),
m_os( os )
XmlWriter( std::ostream& os = Catch::cout() ) : m_os( os )
{
writeDeclaration();
}
@ -233,8 +222,8 @@ namespace Catch {
}
}
bool m_tagIsOpen;
bool m_needsNewline;
bool m_tagIsOpen = false;
bool m_needsNewline = false;
std::vector<std::string> m_tags;
std::string m_indent;
std::ostream& m_os;

View File

@ -17,9 +17,7 @@ namespace Catch {
struct CompactReporter : StreamingReporterBase {
CompactReporter( ReporterConfig const& _config )
: StreamingReporterBase( _config )
{}
using StreamingReporterBase::StreamingReporterBase;
virtual ~CompactReporter();

View File

@ -20,10 +20,7 @@ namespace Catch {
struct ConsoleReporter : StreamingReporterBase {
ConsoleReporter( ReporterConfig const& _config )
: StreamingReporterBase( _config ),
m_headerPrinted( false )
{}
using StreamingReporterBase::StreamingReporterBase;
virtual ~ConsoleReporter() override;
static std::string getDescription() {
@ -435,7 +432,7 @@ namespace Catch {
}
private:
bool m_headerPrinted;
bool m_headerPrinted = false;
};
INTERNAL_CATCH_REGISTER_REPORTER( "console", ConsoleReporter )

View File

@ -51,8 +51,7 @@ namespace Catch {
public:
JunitReporter( ReporterConfig const& _config )
: CumulativeReporterBase( _config ),
xml( _config.stream() ),
m_okToFail( false )
xml( _config.stream() )
{
m_reporterPrefs.shouldRedirectStdOut = true;
}
@ -233,7 +232,7 @@ namespace Catch {
std::ostringstream stdOutForSuite;
std::ostringstream stdErrForSuite;
unsigned int unexpectedExceptions;
bool m_okToFail;
bool m_okToFail = false;
};
INTERNAL_CATCH_REGISTER_REPORTER( "junit", JunitReporter )

View File

@ -21,10 +21,7 @@ namespace Catch {
struct TAPReporter : StreamingReporterBase {
TAPReporter( ReporterConfig const& _config )
: StreamingReporterBase( _config ),
counter(0)
{}
using StreamingReporterBase::StreamingReporterBase;
virtual ~TAPReporter();
@ -62,7 +59,7 @@ namespace Catch {
}
private:
size_t counter;
size_t counter = 0;
class AssertionPrinter {
void operator= ( AssertionPrinter const& );
public:

View File

@ -25,8 +25,7 @@ namespace Catch {
struct TeamCityReporter : StreamingReporterBase {
TeamCityReporter( ReporterConfig const& _config )
: StreamingReporterBase( _config ),
m_headerPrintedForThisSection( false )
: StreamingReporterBase( _config )
{
m_reporterPrefs.shouldRedirectStdOut = true;
}
@ -198,7 +197,7 @@ namespace Catch {
.setInitialIndent( indent ) ) << "\n";
}
private:
bool m_headerPrintedForThisSection;
bool m_headerPrintedForThisSection = false;
};
#ifdef CATCH_IMPL

View File

@ -20,8 +20,7 @@ namespace Catch {
public:
XmlReporter( ReporterConfig const& _config )
: StreamingReporterBase( _config ),
m_xml(_config.stream()),
m_sectionDepth( 0 )
m_xml(_config.stream())
{
m_reporterPrefs.shouldRedirectStdOut = true;
}
@ -219,7 +218,7 @@ namespace Catch {
private:
Timer m_testCaseTimer;
XmlWriter m_xml;
int m_sectionDepth;
int m_sectionDepth = 0;
};
INTERNAL_CATCH_REGISTER_REPORTER( "xml", XmlReporter )