Menu

functionConst false positive

6 days ago
5 days ago
  • Nikita Leontiev

    Nikita Leontiev - 6 days ago

    cppcheck 2.17.1 suggests to use const for method init that changes class member:

    typedef void (*InitFunc)(void**);
    
    template<typename T>
    class Object
    {
    private:
        T *m_ptr;
    public:
        Object() : m_ptr(0) {}
        ~Object()
        {
            if (m_ptr)
                delete m_ptr;
        }
    
        void init(InitFunc func)
        {
            func(reinterpret_cast<void**>(&m_ptr));
        }
    };
    
    template<typename T>
    void init(void **ptr)
    {
        *ptr = new T;
    }
    
    test\main.cpp:16:7: style: inconclusive: Technically the member function 'Object < int >::init' can be const. [functionConst]
     void init(InitFunc func)
          ^
    
     
  • CHR

    CHR - 5 days ago

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

     

    Last edit: CHR 5 days ago

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.