Menu ▾ ▴

FALSE NEGATIVE: `unreadVariable` misses an unused lambda object

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

    Rodri - 2026-09-09

    Hi, I found a false negative in Cppcheck 2.21.0 and 2.22 dev when a local lambda object is initialized but never read.

    Affected tool

    Cppcheck 2.21.0; also reproduced with Cppcheck 2.22 dev

    Affected checker

    Cppcheck unreadVariable

    Minimal reproducer

    void test(int value) {
      auto callback = [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-lambda.cpp
    

    Current behavior

    Cppcheck produces no unreadVariable, unusedVariable, or redundantAssignment diagnostic.

    Expected behavior

    Cppcheck should report line 2 because the value assigned to callback is never read.

     
  • CHR

    CHR - 2026-09-09
     

Log in to post a comment.