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();
                                         ^~~~~~
This commit is contained in:
Xo Wang
2021-10-27 12:10:38 -07:00
committed by Martin Hořeňovský
parent f45dac8fc1
commit 33794a204c
6 changed files with 24 additions and 7 deletions

View File

@@ -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;