Menu

knownConditionTrueFalse false positive

2026-06-05
2026-06-05
  • Nikita Leontiev

    Nikita Leontiev - 2026-06-05

    cppcheck 2.21.0 generates knownConditionTrueFalse for the following code:

    class A
    {
    public:
        template<typename T>
        static bool get(T*)
        {
            return false;
        }
        template<>
        static bool get<int>(int*)
        {
            return true;
        }
    };
    
    class B
    {
    public:
        template<typename T>
        static bool get(T* ptr)
        {
            return A::get(ptr);
        }
    };
    
    cppcheck.exe -q --enable=all .
    test\main.cpp:22:16: style: Return value 'A::get(ptr)' is always false [knownConditionTrueFalse]
      return A::get(ptr);
                   ^
    test\main.cpp:22:16: note: Calling function 'get' returns 0
      return A::get(ptr);
                   ^
    test\main.cpp:22:16: note: Return value 'A::get(ptr)' is always false
      return A::get(ptr);
                   ^
    
     
  • CHR

    CHR - 2026-06-05

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

     

Log in to post a comment.

Auth0 Logo