Menu

InvalidPrintfArgType when using std::abs() in printf()

2022-11-16
2022-11-16
  • Félix-Antoine Constantin

    Hi,
    The following code snippet triggers "invalidPrintfArgType_float" even if the return type of std::abs here is float.

    int main()
    {
        float f = -0.1f;
        printf("%f\n", std::abs(f));
        return 0;
    }
    
    cppcheck --enable=all snippet.cpp
    portability: %f in format string (no. 1) requires 'double' but the argument type is 'int {aka signed int}'. [invalidPrintfArgType_float]
      printf("%f\n", std::abs(f));
    
     
  • CHR

    CHR - 2022-11-16

    Overloads are not handled very well, and the return type is given as int in std.cfg. See this ticket: https://trac.cppcheck.net/ticket/8084

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.