Menu ▾ ▴

functionStatic false positive

5 days ago
4 days ago
  • Nikita Leontiev

    Nikita Leontiev - 5 days ago

    cppcheck 2.22.0 generates functionStatic for the following code:

    #define CASE(index, method) \
        case index: return CASE_##method((method))
    #define CASE_method1(method) method()
    
    class Object
    {
    private:
        int m_num;
    public:
        Object() : m_num(0) {}
        void call(int index)
        {
            switch (index)
            {
                CASE(1, method1);
            }
        }
    private:
        void method1()
        {
            m_num = 1;
        }
    };
    
    int main()
    {
        Object().call(1);
        return 0;
    }
    
    test\main.cpp:11:7: style: The member function 'Object::call' can be static. [functionStatic]
     void call(int index)
          ^
    

    Without parentheses around method, warning is not generated:

    #define CASE(index, method) \
        case index: return CASE_##method(method)
    
     
  • CHR

    CHR - 4 days ago

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

     

Log in to post a comment.