The following generates a false positive knownConditionTrueFalse;
struct Task { int state() const; void poll_for_run_complete(); }; struct TaskList { std::vector<Task*>::iterator active_task_; void do_something() { auto current_active_task_state = (*active_task_)->state(); (*active_task_)->poll_for_run_complete(); auto new_active_task_state = (*active_task_)->state(); // Generates [knownConditionTrueFalse] style warning if (current_active_task_state == new_active_task_state) return; } }
If the iterator is dereferenced before use, there is no warning generated;
Task *task = *active_task; auto current_active_task_state = task->state(); // etc ...
If active_task_ is passed to do_something(), rather than being a member, no warning is generated.
active_task_
do_something()
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/11404
Log in to post a comment.
The following generates a false positive knownConditionTrueFalse;
If the iterator is dereferenced before use, there is no warning generated;
If
active_task_
is passed todo_something()
, rather than being a member, no warning is generated.Last edit: Duncan Palmer 2022-11-24
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/11404