Menu ▾ ▴

functionStatic flags member callbacks

Long Huang
2026-10-28
2026-10-28
  • Long Huang

    Long Huang - 2026-10-28

    Minimal reproduction:

    scratch_functionStatic_callback.h:

    #pragma once
    
    class CallbackReceiver
    {
    public:
       void OnEvent(int)
       {
       }
    };
    

    scratch_functionStatic_callback.cpp:

    #include "scratch_functionStatic_callback.h"
    
    template<typename Receiver>
    void Register(Receiver* receiver, void (Receiver::*callback)(int))
    {
       (receiver->*callback)(1);
    }
    
    int main()
    {
       CallbackReceiver receiver;
       Register(&receiver, &CallbackReceiver::OnEvent);
    }
    

    Expected

    • Expected: OnEvent remains a non-static member, registration requires a
      void (Receiver::*)(int), while a static method produces a different
      function-pointer type.

    Actual

    when Cppcheck analyzes the header by itself:

    scratch_functionStatic_callback.h:6:9: style: The member function 'CallbackReceiver::OnEvent' can be static. [functionStatic]

     
  • Long Huang

    Long Huang - 2026-10-28

    For the record, these warnings appear when cppcheck only analyzes the header & not the translation unit. So maybe not really a defect but just how it goes...

     

Log in to post a comment.