Menu ▾ ▴

FALSE NEGATIVE: `unreadVariable` misses a dead nested assignment

Rodri
2026-09-09
2026-09-10
  • Rodri

    Rodri - 2026-09-09

    Hi, I found a false negative in Cppcheck 2.21.0 and 2.22 dev when an assignment's expression value is returned but the value stored in the local variable is never read.

    Affected tool

    Cppcheck 2.21.0; also reproduced with Cppcheck 2.22 dev

    Affected checker

    Cppcheck unreadVariable

    Minimal reproducer

    int make_value();
    
    int test() {
      int value;
      return value = make_value();
    }
    

    Reproduction command

    cppcheck --version
    cppcheck --enable=style --inconclusive --std=c++17 --checkers-report=checkers.txt --template='{file}:{line}:{column}: [{id}] {message}' cppcheck-unreadvariable-fn-nested-assignment.cpp
    

    Current behavior

    Cppcheck produces no unreadVariable diagnostic.

    Expected behavior

    Cppcheck should report line 5 because the assignment expression supplies the return value directly and the value stored in value is never read from the variable.

     
  • CHR

    CHR - 2026-09-10

    Thanks for reporting, example added here: https://trac.cppcheck.net/ticket/11222

     

Log in to post a comment.