Cleanup some stuff found by MSVC's /analyze

* Added some missing `noexcept`s on custom destructors.
* Fixed `std::move` being called on a const-reference.
* Initialized `ScopedMessage::m_moved` in class definition, instead
of doing so in constructors explicitly.
* Turned some `enum`s into `enum class`es.
* Initialized `StreamingReporterBase::currentTestCaseInfo` in class
definition.
* Some cleanups in SelfTest code.
This commit is contained in:
Martin Hořeňovský 2020-08-19 17:44:22 +02:00
parent 2e480b6e56
commit 1a97af45f1
No known key found for this signature in database
GPG Key ID: DE48307B8B0D381A
8 changed files with 27 additions and 27 deletions

View File

@ -81,14 +81,15 @@ namespace Catch {
BenchmarkFunction(Fun&& fun) BenchmarkFunction(Fun&& fun)
: f(new model<typename std::decay<Fun>::type>(std::forward<Fun>(fun))) {} : f(new model<typename std::decay<Fun>::type>(std::forward<Fun>(fun))) {}
BenchmarkFunction(BenchmarkFunction&& that) BenchmarkFunction( BenchmarkFunction&& that ) noexcept:
: f(std::move(that.f)) {} f( std::move( that.f ) ) {}
BenchmarkFunction(BenchmarkFunction const& that) BenchmarkFunction(BenchmarkFunction const& that)
: f(that.f->clone()) {} : f(that.f->clone()) {}
BenchmarkFunction& operator=(BenchmarkFunction&& that) { BenchmarkFunction&
f = std::move(that.f); operator=( BenchmarkFunction&& that ) noexcept {
f = std::move( that.f );
return *this; return *this;
} }

View File

@ -26,16 +26,14 @@ namespace Catch {
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
ScopedMessage::ScopedMessage( MessageBuilder const& builder ) ScopedMessage::ScopedMessage( MessageBuilder const& builder ):
: m_info( builder.m_info ), m_moved() m_info( builder.m_info ) {
{
m_info.message = builder.m_stream.str(); m_info.message = builder.m_stream.str();
getResultCapture().pushScopedMessage( m_info ); getResultCapture().pushScopedMessage( m_info );
} }
ScopedMessage::ScopedMessage( ScopedMessage&& old ) ScopedMessage::ScopedMessage( ScopedMessage&& old ) noexcept:
: m_info( old.m_info ), m_moved() m_info( std::move( old.m_info ) ) {
{
old.m_moved = true; old.m_moved = true;
} }

View File

@ -49,11 +49,11 @@ namespace Catch {
public: public:
explicit ScopedMessage( MessageBuilder const& builder ); explicit ScopedMessage( MessageBuilder const& builder );
ScopedMessage( ScopedMessage& duplicate ) = delete; ScopedMessage( ScopedMessage& duplicate ) = delete;
ScopedMessage( ScopedMessage&& old ); ScopedMessage( ScopedMessage&& old ) noexcept;
~ScopedMessage(); ~ScopedMessage();
MessageInfo m_info; MessageInfo m_info;
bool m_moved; bool m_moved = false;
}; };
class Capturer { class Capturer {

View File

@ -41,7 +41,7 @@ namespace Catch {
} }
std::vector<TagInfo> infos; infos.reserve(tagCounts.size()); std::vector<TagInfo> infos; infos.reserve(tagCounts.size());
for (auto const& tagc : tagCounts) { for (auto& tagc : tagCounts) {
infos.push_back(std::move(tagc.second)); infos.push_back(std::move(tagc.second));
} }

View File

@ -71,7 +71,7 @@ namespace Catch {
LazyStat<TestRunInfo> currentTestRunInfo; LazyStat<TestRunInfo> currentTestRunInfo;
LazyStat<GroupInfo> currentGroupInfo; LazyStat<GroupInfo> currentGroupInfo;
TestCaseInfo const* currentTestCaseInfo; TestCaseInfo const* currentTestCaseInfo = nullptr;
std::vector<SectionInfo> m_sectionStack; std::vector<SectionInfo> m_sectionStack;
}; };

View File

@ -192,8 +192,9 @@ std::size_t& findMax(std::size_t& i, std::size_t& j, std::size_t& k) {
return k; return k;
} }
enum class Justification { Left, Right };
struct ColumnInfo { struct ColumnInfo {
enum Justification { Left, Right };
std::string name; std::string name;
int width; int width;
Justification justification; Justification justification;
@ -335,7 +336,7 @@ public:
auto padding = (strSize + 1 < static_cast<std::size_t>(colInfo.width)) auto padding = (strSize + 1 < static_cast<std::size_t>(colInfo.width))
? std::string(colInfo.width - (strSize + 1), ' ') ? std::string(colInfo.width - (strSize + 1), ' ')
: std::string(); : std::string();
if (colInfo.justification == ColumnInfo::Left) if (colInfo.justification == Justification::Left)
tp.m_os << colStr << padding << ' '; tp.m_os << colStr << padding << ' ';
else else
tp.m_os << padding << colStr << ' '; tp.m_os << padding << colStr << ' ';
@ -358,19 +359,19 @@ ConsoleReporter::ConsoleReporter(ReporterConfig const& config)
if (config.fullConfig()->benchmarkNoAnalysis()) if (config.fullConfig()->benchmarkNoAnalysis())
{ {
return{ return{
{ "benchmark name", CATCH_CONFIG_CONSOLE_WIDTH - 43, ColumnInfo::Left }, { "benchmark name", CATCH_CONFIG_CONSOLE_WIDTH - 43, Justification::Left },
{ " samples", 14, ColumnInfo::Right }, { " samples", 14, Justification::Right },
{ " iterations", 14, ColumnInfo::Right }, { " iterations", 14, Justification::Right },
{ " mean", 14, ColumnInfo::Right } { " mean", 14, Justification::Right }
}; };
} }
else else
{ {
return{ return{
{ "benchmark name", CATCH_CONFIG_CONSOLE_WIDTH - 43, ColumnInfo::Left }, { "benchmark name", CATCH_CONFIG_CONSOLE_WIDTH - 43, Justification::Left },
{ "samples mean std dev", 14, ColumnInfo::Right }, { "samples mean std dev", 14, Justification::Right },
{ "iterations low mean low std dev", 14, ColumnInfo::Right }, { "iterations low mean low std dev", 14, Justification::Right },
{ "estimated high mean high std dev", 14, ColumnInfo::Right } { "estimated high mean high std dev", 14, Justification::Right }
}; };
} }
}())) {} }())) {}

View File

@ -104,10 +104,10 @@ namespace {
move_detector(move_detector const& rhs) = default; move_detector(move_detector const& rhs) = default;
move_detector& operator=(move_detector const& rhs) = default; move_detector& operator=(move_detector const& rhs) = default;
move_detector(move_detector&& rhs) { move_detector(move_detector&& rhs) noexcept {
rhs.has_moved = true; rhs.has_moved = true;
} }
move_detector& operator=(move_detector&& rhs) { move_detector& operator=(move_detector&& rhs) noexcept {
rhs.has_moved = true; rhs.has_moved = true;
return *this; return *this;
} }

View File

@ -185,7 +185,7 @@ struct Obj
{ {
Obj():prop(&p){} Obj():prop(&p){}
int p; int p = 0;
int* prop; int* prop;
}; };