Menu

FALSE NEGATIVE: `redundantInitialization` misses an explicit float cast

Rodri
5 days ago
4 days ago
  • Rodri

    Rodri - 5 days ago

    Cppcheck 2.21.0 misses an initialization whose explicit floating conversion is overwritten before the initialized value is read.

    Affected tool and checker

    Cppcheck 2.21.0, redundantInitialization.

    Minimal reproducer

    void initialize(double &);
    
    float test() {
      double input;
      initialize(input);
      float value = (float)input;
      value = 3.14f;
      return value;
    }
    

    Reproduction command

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

    Current behavior

    Cppcheck emits no redundantInitialization diagnostic. The plain form
    float value = input; does produce redundantInitialization, isolating
    explicit conversion handling.

    Expected behavior

    Cppcheck should report that the initialized value is overwritten before it is read.

     
  • CHR

    CHR - 4 days ago

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

     

Log in to post a comment.