Skip to content

Commit 11a96e1

Browse files
committed
Cleanups from static analysis
1 parent 10f6248 commit 11a96e1

11 files changed

Lines changed: 35 additions & 33 deletions

.clang-tidy

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Checks: >-
3232
-modernize-deprecated-headers,
3333
,# There's a lot of these and most of them are probably not useful,
3434
-modernize-pass-by-value,
35+
-modernize-use-string-view, # We support C++14,
3536
3637
performance-*,
3738
performance-enum-size,
@@ -58,6 +59,8 @@ Checks: >-
5859
-readability-uppercase-literal-suffix,
5960
-readability-use-anyofallof,
6061
-readability-avoid-return-with-void-value,
62+
,# We prefer if defined(FOO) form because it is easier to extend later,
63+
-readability-use-concise-preprocessor-directives,
6164
6265
,# time hogs,
6366
-bugprone-throw-keyword-missing,

src/catch2/benchmark/detail/catch_analyse.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ namespace Catch {
3636
samples.data(), samples.data() + samples.size() );
3737

3838
auto wrap_estimate = [](Estimate<double> e) {
39-
return Estimate<FDuration> {
40-
FDuration(e.point),
41-
FDuration(e.lower_bound),
42-
FDuration(e.upper_bound),
43-
e.confidence_interval,
39+
return Estimate<FDuration>{
40+
FDuration( e.point ),
41+
FDuration( e.lower_bound ),
42+
FDuration( e.upper_bound ),
43+
e.confidence_interval,
4444
};
4545
};
4646
std::vector<FDuration> samples2;

src/catch2/internal/catch_run_context.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -461,14 +461,13 @@ namespace Catch {
461461
Detail::g_lastAssertionPassed = true;
462462
} else if (!result.succeeded()) {
463463
Detail::g_lastAssertionPassed = false;
464-
if (result.isOk()) {
465-
}
466-
else if( m_activeTestCase->getTestCaseInfo().okToFail() ) // Read from a shared state established before the threads could start, this is fine
464+
if (result.isOk()) {}
465+
else if( m_activeTestCase->getTestCaseInfo().okToFail() ) { // Read from a shared state established before the threads could start, this is fine
467466
m_atomicAssertionCount.failedButOk++;
468-
else
467+
} else {
469468
m_atomicAssertionCount.failed++;
470-
}
471-
else {
469+
}
470+
} else {
472471
Detail::g_lastAssertionPassed = true;
473472
}
474473

@@ -650,7 +649,7 @@ namespace Catch {
650649
// and since IResultCapture::getLastResult is deprecated,
651650
// we will leave it as is, until it is finally removed.
652651
Detail::LockGuard _( m_assertionMutex );
653-
return &(*m_lastResult);
652+
return &*m_lastResult;
654653
}
655654

656655
void RunContext::exceptionEarlyReported() {
@@ -902,7 +901,7 @@ namespace Catch {
902901
}
903902

904903
void RunContext::populateReaction( AssertionReaction& reaction,
905-
bool has_normal_disposition ) {
904+
bool has_normal_disposition ) const {
906905
reaction.shouldDebugBreak = m_shouldDebugBreak;
907906
reaction.shouldThrow = aborting() || has_normal_disposition;
908907
}

src/catch2/internal/catch_run_context.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ namespace Catch {
123123
ITransientExpression const *expr,
124124
bool negated );
125125

126-
void populateReaction( AssertionReaction& reaction, bool has_normal_disposition );
126+
void populateReaction( AssertionReaction& reaction, bool has_normal_disposition ) const;
127127

128128
// Creates dummy info for unexpected exceptions/fatal errors,
129129
// where we do not have the access to one, but we still need

src/catch2/internal/catch_tag_alias_registry.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ namespace Catch {
1616

1717
TagAlias const* TagAliasRegistry::find( std::string const& alias ) const {
1818
auto it = m_registry.find( alias );
19-
if( it != m_registry.end() )
20-
return &(it->second);
21-
else
19+
if ( it != m_registry.end() ) {
20+
return &it->second;
21+
} else {
2222
return nullptr;
23+
}
2324
}
2425

2526
std::string TagAliasRegistry::expandAliases( std::string const& unexpandedTestSpec ) const {

src/catch2/internal/catch_test_failure_exception.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ namespace Catch {
1414

1515
void throw_test_failure_exception() {
1616
#if !defined( CATCH_CONFIG_DISABLE_EXCEPTIONS )
17-
throw TestFailureException{};
17+
throw TestFailureException{}; //NOLINT(bugprone-std-exception-baseclass)
1818
#else
1919
CATCH_ERROR( "Test failure requires aborting test!" );
2020
#endif
2121
}
2222

2323
void throw_test_skip_exception() {
2424
#if !defined( CATCH_CONFIG_DISABLE_EXCEPTIONS )
25-
throw Catch::TestSkipException();
25+
throw Catch::TestSkipException(); //NOLINT(bugprone-std-exception-baseclass)
2626
#else
2727
CATCH_ERROR( "Explicitly skipping tests during runtime requires exceptions" );
2828
#endif

src/catch2/internal/catch_test_registry.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ struct AutoReg : Detail::NonCopyable {
124124
namespace Catch {
125125
namespace Detail {
126126
struct DummyUse {
127-
DummyUse( void ( * )( int ), Catch::NameAndTags const& );
127+
DummyUse( void ( * )( int ), Catch::NameAndTags const& ) noexcept;
128128
};
129129
} // namespace Detail
130130
} // namespace Catch

src/catch2/reporters/catch_reporter_cumulative_base.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ namespace Catch {
2020
bool operator()(
2121
Detail::unique_ptr<CumulativeReporterBase::SectionNode> const&
2222
node ) const {
23-
return (
24-
( node->stats.sectionInfo.name == m_other.name ) &&
25-
( node->stats.sectionInfo.lineInfo == m_other.lineInfo ) );
23+
return node->stats.sectionInfo.name == m_other.name
24+
&& node->stats.sectionInfo.lineInfo == m_other.lineInfo;
2625
}
2726
void operator=( BySectionInfo const& ) = delete;
2827

tests/SelfTest/IntrospectiveTests/Integer.tests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ namespace {
3939
// -------------------------
4040
// | a | b | c | d |
4141

42-
#define CarryBits( x ) ( x >> 32 )
43-
#define Digits( x ) ( x & 0xFF'FF'FF'FF )
42+
#define CarryBits( x ) ( (x) >> 32 )
43+
#define Digits( x ) ( (x) & 0xFF'FF'FF'FF )
4444

4545
auto r2l2 = Digits( rhs ) * Digits( lhs );
4646
auto r2l1 = Digits( rhs ) * CarryBits( lhs );

tests/SelfTest/UsageTests/ToStringPair.tests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ TEST_CASE( "std::vector<std::pair<std::string,int> > -> toString", "[toString][p
2727

2828
// This is pretty contrived - I figure if this works, anything will...
2929
TEST_CASE( "pair<pair<int,const char *,pair<std::string,int> > -> toString", "[toString][pair]" ) {
30-
typedef std::pair<int,const char *> left_t;
31-
typedef std::pair<std::string,int> right_t;
30+
using left_t = std::pair<int,const char *>;
31+
using right_t = std::pair<std::string,int>;
3232

3333
left_t left( 42, "Arthur" );
3434
right_t right( "Ford", 24 );

0 commit comments

Comments
 (0)