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 committed Nov 22, 2021
1 parent 6d6590b commit 9680539
Showing 1 changed file with 6 additions and 1 deletion.
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

0 comments on commit 9680539

Please sign in to comment.