Menu

FALSE NEGATIVE: `redundantAssignment` misses an overwritten zero value

Rodri
5 days ago
4 days ago
  • Rodri

    Rodri - 5 days ago

    Cppcheck 2.21.0 does not report a dead first store when its value is zero,
    although the otherwise equivalent nonzero store is reported as
    redundantAssignment.

    Affected tool and checker

    Cppcheck 2.21.0, redundantAssignment.

    Minimal reproducer

    void test() {
      int value;
      value = 0;
      value = 1;
      (void)value;
    }
    

    Reproduction command

    cppcheck --enable=all --inconclusive --check-level=exhaustive --std=c++17 \
      --template='{file}:{line}:{column}: [{id}] {message}' \
      mutant-cppcheck-redundantassignment-fn-zero-overwrite.cpp
    

    Current behavior

    Cppcheck emits no redundantAssignment diagnostic. Replacing 0 with 42
    produces redundantAssignment at the first assignment, isolating the
    zero-value branch.

    Expected behavior

    Cppcheck should report that the first value assigned to value is overwritten
    before it is read.

     
  • CHR

    CHR - 4 days ago

    There is a deliberate bailout to allow "trivial" initialization.

     

Log in to post a comment.