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)
: f(new model<typename std::decay<Fun>::type>(std::forward<Fun>(fun))) {}
BenchmarkFunction(BenchmarkFunction&& that)
: f(std::move(that.f)) {}
BenchmarkFunction( BenchmarkFunction&& that ) noexcept:
f( std::move( that.f ) ) {}
BenchmarkFunction(BenchmarkFunction const& that)
: f(that.f->clone()) {}
BenchmarkFunction& operator=(BenchmarkFunction&& that) {
f = std::move(that.f);
BenchmarkFunction&
operator=( BenchmarkFunction&& that ) noexcept {
f = std::move( that.f );
return *this;
}

View File

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

View File

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

View File

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

View File

@ -71,7 +71,7 @@ namespace Catch {
LazyStat<TestRunInfo> currentTestRunInfo;
LazyStat<GroupInfo> currentGroupInfo;
TestCaseInfo const* currentTestCaseInfo;
TestCaseInfo const* currentTestCaseInfo = nullptr;
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;
}
enum class Justification { Left, Right };
struct ColumnInfo {
enum Justification { Left, Right };
std::string name;
int width;
Justification justification;
@ -335,7 +336,7 @@ public:
auto padding = (strSize + 1 < static_cast<std::size_t>(colInfo.width))
? std::string(colInfo.width - (strSize + 1), ' ')
: std::string();
if (colInfo.justification == ColumnInfo::Left)
if (colInfo.justification == Justification::Left)
tp.m_os << colStr << padding << ' ';
else
tp.m_os << padding << colStr << ' ';
@ -358,19 +359,19 @@ ConsoleReporter::ConsoleReporter(ReporterConfig const& config)
if (config.fullConfig()->benchmarkNoAnalysis())
{
return{
{ "benchmark name", CATCH_CONFIG_CONSOLE_WIDTH - 43, ColumnInfo::Left },
{ " samples", 14, ColumnInfo::Right },
{ " iterations", 14, ColumnInfo::Right },
{ " mean", 14, ColumnInfo::Right }
{ "benchmark name", CATCH_CONFIG_CONSOLE_WIDTH - 43, Justification::Left },
{ " samples", 14, Justification::Right },
{ " iterations", 14, Justification::Right },
{ " mean", 14, Justification::Right }
};
}
else
{
return{
{ "benchmark name", CATCH_CONFIG_CONSOLE_WIDTH - 43, ColumnInfo::Left },
{ "samples mean std dev", 14, ColumnInfo::Right },
{ "iterations low mean low std dev", 14, ColumnInfo::Right },
{ "estimated high mean high std dev", 14, ColumnInfo::Right }
{ "benchmark name", CATCH_CONFIG_CONSOLE_WIDTH - 43, Justification::Left },
{ "samples mean std dev", 14, Justification::Right },
{ "iterations low mean low std dev", 14, Justification::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& operator=(move_detector const& rhs) = default;
move_detector(move_detector&& rhs) {
move_detector(move_detector&& rhs) noexcept {
rhs.has_moved = true;
}
move_detector& operator=(move_detector&& rhs) {
move_detector& operator=(move_detector&& rhs) noexcept {
rhs.has_moved = true;
return *this;
}

View File

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