Skip to content

Commit

Permalink
Fix clang analyzer warning about FilterGenerator
Browse files Browse the repository at this point in the history
Refactor FilterGenerator to remove ctor call to overridden method next()
in order to address clang static analyzer diagnostic:

catch2-src/single_include/catch2/catch.hpp:4166:42: note: Call to virtual method 'FilterGenerator::next' during construction bypasses virtual dispatch
                auto has_initial_value = next();
                                         ^~~~~~
  • Loading branch information
GHF authored and horenmar committed Nov 24, 2021
1 parent f45dac8 commit 33794a2
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 7 deletions.
7 changes: 6 additions & 1 deletion include/internal/catch_generators_generic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ namespace Generators {
if (!m_predicate(m_generator.get())) {
// It might happen that there are no values that pass the
// filter. In that case we throw an exception.
auto has_initial_value = next();
auto has_initial_value = nextImpl();
if (!has_initial_value) {
Catch::throw_exception(GeneratorException("No valid value found in filtered generator"));
}
Expand All @@ -75,6 +75,11 @@ namespace Generators {
}

bool next() override {
return nextImpl();
}

private:
bool nextImpl() {
bool success = m_generator.next();
if (!success) {
return false;
Expand Down
1 change: 1 addition & 0 deletions projects/SelfTest/Baselines/compact.sw.approved.txt
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,7 @@ GeneratorsImpl.tests.cpp:<line number>: passed: gen.next() for: true
GeneratorsImpl.tests.cpp:<line number>: passed: gen.get() == 3 for: 3 == 3
GeneratorsImpl.tests.cpp:<line number>: passed: !(gen.next()) for: !false
GeneratorsImpl.tests.cpp:<line number>: passed: filter([] (int) { return false; }, value(1)), Catch::GeneratorException
GeneratorsImpl.tests.cpp:<line number>: passed: filter( []( int ) { return false; }, values( { 1, 2, 3 } ) ), Catch::GeneratorException
GeneratorsImpl.tests.cpp:<line number>: passed: gen.get() == 1 for: 1 == 1
GeneratorsImpl.tests.cpp:<line number>: passed: gen.next() for: true
GeneratorsImpl.tests.cpp:<line number>: passed: gen.get() == 2 for: 2 == 2
Expand Down
2 changes: 1 addition & 1 deletion projects/SelfTest/Baselines/console.std.approved.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1421,5 +1421,5 @@ due to unexpected exception with message:

===============================================================================
test cases: 323 | 248 passed | 70 failed | 5 failed as expected
assertions: 1763 | 1607 passed | 131 failed | 25 failed as expected
assertions: 1764 | 1608 passed | 131 failed | 25 failed as expected

5 changes: 4 additions & 1 deletion projects/SelfTest/Baselines/console.sw.approved.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4968,6 +4968,9 @@ with expansion:
GeneratorsImpl.tests.cpp:<line number>: PASSED:
REQUIRE_THROWS_AS( filter([] (int) { return false; }, value(1)), Catch::GeneratorException )

GeneratorsImpl.tests.cpp:<line number>: PASSED:
REQUIRE_THROWS_AS( filter( []( int ) { return false; }, values( { 1, 2, 3 } ) ), Catch::GeneratorException )

-------------------------------------------------------------------------------
Generators internals
Take generator
Expand Down Expand Up @@ -14179,5 +14182,5 @@ Misc.tests.cpp:<line number>: PASSED:

===============================================================================
test cases: 323 | 232 passed | 86 failed | 5 failed as expected
assertions: 1780 | 1607 passed | 148 failed | 25 failed as expected
assertions: 1781 | 1608 passed | 148 failed | 25 failed as expected

2 changes: 1 addition & 1 deletion projects/SelfTest/Baselines/junit.sw.approved.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuitesloose text artifact
>
<testsuite name="<exe-name>" errors="17" failures="132" tests="1781" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
<testsuite name="<exe-name>" errors="17" failures="132" tests="1782" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
<properties>
<property name="filters" value="~[!nonportable]~[!benchmark]~[approvals]"/>
<property name="random-seed" value="1"/>
Expand Down
14 changes: 11 additions & 3 deletions projects/SelfTest/Baselines/xml.sw.approved.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5720,7 +5720,15 @@ Nor would this
filter([] (int) { return false; }, value(1)), Catch::GeneratorException
</Expanded>
</Expression>
<OverallResults successes="5" failures="0" expectedFailures="0"/>
<Expression success="true" type="REQUIRE_THROWS_AS" filename="projects/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" >
<Original>
filter( []( int ) { return false; }, values( { 1, 2, 3 } ) ), Catch::GeneratorException
</Original>
<Expanded>
filter( []( int ) { return false; }, values( { 1, 2, 3 } ) ), Catch::GeneratorException
</Expanded>
</Expression>
<OverallResults successes="6" failures="0" expectedFailures="0"/>
</Section>
<Section name="Take generator" filename="projects/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" >
<Section name="Take less" filename="projects/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" >
Expand Down Expand Up @@ -16759,9 +16767,9 @@ loose text artifact
</Section>
<OverallResult success="true"/>
</TestCase>
<OverallResults successes="1607" failures="149" expectedFailures="25"/>
<OverallResults successes="1608" failures="149" expectedFailures="25"/>
<OverallResultsCases successes="232" failures="86" expectedFailures="5"/>
</Group>
<OverallResults successes="1607" failures="148" expectedFailures="25"/>
<OverallResults successes="1608" failures="148" expectedFailures="25"/>
<OverallResultsCases successes="232" failures="86" expectedFailures="5"/>
</Catch>

0 comments on commit 33794a2

Please sign in to comment.