Menu ▾ ▴

knownConditionTrueFalse - callback-driven event-loop flag considered constant

Long Huang
2026-10-29
2026-10-30
  • Long Huang

    Long Huang - 2026-10-29

    Reproduction

    #include <cassert>
    
    class EventLoop
    {
    public:
       static void ProcessEvents();
    };
    
    class Listener
    {
    public:
       bool Start()
       {
          Waiting = true;
          for(int remaining = 2; remaining > 0 && Waiting; --remaining)
          {
             EventLoop::ProcessEvents();
          }
          return !Waiting;
       }
    
       void Ready() { Waiting = false; }
    
    private:
       bool Waiting = false;
    };
    
    Listener* ActiveListener = nullptr;
    
    void EventLoop::ProcessEvents()
    {
       ActiveListener->Ready();
    }
    
    int main()
    {
       Listener listener;
       ActiveListener = &listener;
       const bool started = listener.Start();
       assert(started);
    }
    

    Expected:

    Neither condition is constant, dispatch calls Ready() and changes
    the member before the next iteration.

    Actual:

    scratch_outer_eventloop.cpp:15:47: warning: Condition 'Waiting' is always true [knownConditionTrueFalse]
    scratch_outer_eventloop.cpp:19:14: warning: Return value '!Waiting' is always false [knownConditionTrueFalse]
    
     
  • CHR

    CHR - 2026-10-30

    Looks like a variation of Looks like a variation of https://trac.cppcheck.net/ticket/11562

     

Log in to post a comment.