diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 054348037..0ab6c3fca 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -7305,8 +7305,14 @@ static bool needsInitialization(const Variable* var, bool cpp) return true; if (var->type() && var->type()->needInitialization == Type::NeedInitialization::True) return true; - if (var->valueType() && (var->valueType()->isPrimitive() || var->valueType()->type == ValueType::Type::POD)) - return true; + if (var->valueType()) { + if (var->valueType()->isPrimitive()) + return true; + if (var->valueType()->type == ValueType::Type::POD) + return true; + if (var->valueType()->type == ValueType::Type::ITERATOR) + return true; + } return false; } diff --git a/test/cfg/std.cpp b/test/cfg/std.cpp index e473c8942..b2f793ae4 100644 --- a/test/cfg/std.cpp +++ b/test/cfg/std.cpp @@ -413,19 +413,19 @@ void uninitvar_std_next(const std::vector &v, int count) if (std::next(v.begin(), count) != v.end()) {} std::vector::iterator it; - // TODO-cppcheck-suppress uninitvar + // cppcheck-suppress uninitvar if (std::next(it) != v.end()) {} std::vector::const_iterator const_it; - // TODO-cppcheck-suppress uninitvar + // cppcheck-suppress uninitvar if (std::next(const_it) != v.end()) {} std::vector::reverse_iterator rit; - // TODO-cppcheck-suppress uninitvar + // cppcheck-suppress uninitvar if (std::next(rit) != v.rend()) {} std::vector::const_reverse_iterator const_rit; - // TODO-cppcheck-suppress uninitvar + // cppcheck-suppress uninitvar if (std::next(const_rit) != v.rend()) {} } @@ -436,19 +436,19 @@ void uninitvar_std_prev(const std::vector &v, int count) if (std::prev(v.begin(), count) != v.end()) {} std::vector::iterator it; - // TODO-cppcheck-suppress uninitvar + // cppcheck-suppress uninitvar if (std::prev(it) != v.end()) {} std::vector::const_iterator const_it; - // TODO-cppcheck-suppress uninitvar + // cppcheck-suppress uninitvar if (std::prev(const_it) != v.end()) {} std::vector::reverse_iterator rit; - // TODO-cppcheck-suppress uninitvar + // cppcheck-suppress uninitvar if (std::prev(rit) != v.rend()) {} std::vector::const_reverse_iterator const_rit; - // TODO-cppcheck-suppress uninitvar + // cppcheck-suppress uninitvar if (std::prev(const_rit) != v.rend()) {} } @@ -4095,7 +4095,7 @@ void stdalgorithm(const std::list &ints1, const std::list &ints2) // #9455 std::list::const_iterator uninitItBegin; std::list::const_iterator uninitItEnd; - // @todo cppcheck-suppress uninitvar + // cppcheck-suppress uninitvar if (std::find(uninitItBegin, uninitItEnd, 123) == uninitItEnd) {} //