From 33794a204c00158b15eeda38bd2e30a5a57533fc Mon Sep 17 00:00:00 2001 From: Xo Wang Date: Wed, 27 Oct 2021 12:10:38 -0700 Subject: [PATCH] Fix clang analyzer warning about FilterGenerator 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(); ^~~~~~ --- include/internal/catch_generators_generic.hpp | 7 ++++++- .../SelfTest/Baselines/compact.sw.approved.txt | 1 + .../SelfTest/Baselines/console.std.approved.txt | 2 +- .../SelfTest/Baselines/console.sw.approved.txt | 5 ++++- projects/SelfTest/Baselines/junit.sw.approved.txt | 2 +- projects/SelfTest/Baselines/xml.sw.approved.txt | 14 +++++++++++--- 6 files changed, 24 insertions(+), 7 deletions(-) diff --git a/include/internal/catch_generators_generic.hpp b/include/internal/catch_generators_generic.hpp index c3410147..b2a0af5e 100644 --- a/include/internal/catch_generators_generic.hpp +++ b/include/internal/catch_generators_generic.hpp @@ -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")); } @@ -75,6 +75,11 @@ namespace Generators { } bool next() override { + return nextImpl(); + } + + private: + bool nextImpl() { bool success = m_generator.next(); if (!success) { return false; diff --git a/projects/SelfTest/Baselines/compact.sw.approved.txt b/projects/SelfTest/Baselines/compact.sw.approved.txt index 0d12ebb9..d66cb98e 100644 --- a/projects/SelfTest/Baselines/compact.sw.approved.txt +++ b/projects/SelfTest/Baselines/compact.sw.approved.txt @@ -628,6 +628,7 @@ GeneratorsImpl.tests.cpp:: passed: gen.next() for: true GeneratorsImpl.tests.cpp:: passed: gen.get() == 3 for: 3 == 3 GeneratorsImpl.tests.cpp:: passed: !(gen.next()) for: !false GeneratorsImpl.tests.cpp:: passed: filter([] (int) { return false; }, value(1)), Catch::GeneratorException +GeneratorsImpl.tests.cpp:: passed: filter( []( int ) { return false; }, values( { 1, 2, 3 } ) ), Catch::GeneratorException GeneratorsImpl.tests.cpp:: passed: gen.get() == 1 for: 1 == 1 GeneratorsImpl.tests.cpp:: passed: gen.next() for: true GeneratorsImpl.tests.cpp:: passed: gen.get() == 2 for: 2 == 2 diff --git a/projects/SelfTest/Baselines/console.std.approved.txt b/projects/SelfTest/Baselines/console.std.approved.txt index 9de49d9a..c29715f0 100644 --- a/projects/SelfTest/Baselines/console.std.approved.txt +++ b/projects/SelfTest/Baselines/console.std.approved.txt @@ -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 diff --git a/projects/SelfTest/Baselines/console.sw.approved.txt b/projects/SelfTest/Baselines/console.sw.approved.txt index 7f663129..2318ebea 100644 --- a/projects/SelfTest/Baselines/console.sw.approved.txt +++ b/projects/SelfTest/Baselines/console.sw.approved.txt @@ -4968,6 +4968,9 @@ with expansion: GeneratorsImpl.tests.cpp:: PASSED: REQUIRE_THROWS_AS( filter([] (int) { return false; }, value(1)), Catch::GeneratorException ) +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE_THROWS_AS( filter( []( int ) { return false; }, values( { 1, 2, 3 } ) ), Catch::GeneratorException ) + ------------------------------------------------------------------------------- Generators internals Take generator @@ -14179,5 +14182,5 @@ Misc.tests.cpp:: 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 diff --git a/projects/SelfTest/Baselines/junit.sw.approved.txt b/projects/SelfTest/Baselines/junit.sw.approved.txt index b7e55e04..e2a504f5 100644 --- a/projects/SelfTest/Baselines/junit.sw.approved.txt +++ b/projects/SelfTest/Baselines/junit.sw.approved.txt @@ -1,7 +1,7 @@ - + diff --git a/projects/SelfTest/Baselines/xml.sw.approved.txt b/projects/SelfTest/Baselines/xml.sw.approved.txt index 0a2d3377..30856484 100644 --- a/projects/SelfTest/Baselines/xml.sw.approved.txt +++ b/projects/SelfTest/Baselines/xml.sw.approved.txt @@ -5720,7 +5720,15 @@ Nor would this filter([] (int) { return false; }, value(1)), Catch::GeneratorException - + + + filter( []( int ) { return false; }, values( { 1, 2, 3 } ) ), Catch::GeneratorException + + + filter( []( int ) { return false; }, values( { 1, 2, 3 } ) ), Catch::GeneratorException + + +
@@ -16759,9 +16767,9 @@ loose text artifact
- + - +