Menu

FALSE NEGATIVE:`zerodiv` misses a zero captured by a lambda

Rodri
2026-08-29
6 days ago
  • Rodri

    Rodri - 2026-08-29

    Hi, I found a false negative in Cppcheck 2.21.0 when a lambda captures a known zero value used as the divisor.

    Affected checker

    Cppcheck zerodiv

    Minimal reproducer

    int divide_by_lambda_capture() {
      int value = 0;
      return [=] { return 1 / value; }();
    }
    

    Reproduction command

    cppcheck --version
    cppcheck --enable=warning --std=c++11 --checkers-report=checkers.txt --template='{file}:{line}:{column}: [{id}] {message}' cppcheck-zerodiv-fn-lambda-capture.cpp
    

    Current behavior

    Cppcheck produces neither a zerodiv nor a zerodivcond diagnostic. The checker report lists CheckOther::checkZeroDivision as active.

    Expected behavior

    Cppcheck should report zerodiv at line 3 because the lambda captures value after it is initialized to zero.

     
  • CHR

    CHR - 6 days ago

    Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/14996

     

Log in to post a comment.