feat(tidy): add fairmq-bugprone-ondata-with-conditionalrun

- Report devices that register a data callback with OnData() and also
  override ConditionalRun(). With data callbacks, Device::RunWrapper()
  runs only the callbacks, so ConditionalRun() is dead code.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Claude
2026-11-09 23:14:01 +00:00
parent b113f0a7d8
commit 42952bfa42
6 changed files with 150 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
#include <fairmq/Device.h>
struct Both : fair::mq::Device
{
Both() { OnData("data", &Both::HandleData); }
// CHECK-MESSAGES: :[[@LINE+1]]:10: warning: 'Both' overrides 'ConditionalRun()' and registers a data callback with 'OnData()'; 'ConditionalRun()' never runs [fairmq-bugprone-ondata-with-conditionalrun]
bool ConditionalRun() override { return true; }
bool HandleData(fair::mq::MessagePtr&, int) { return true; }
};
struct Lambda : fair::mq::Device
{
void InitTask() override
{
OnData("data", [](fair::mq::MessagePtr&, int) { return true; });
}
bool ConditionalRun() override;
};
// CHECK-MESSAGES: :[[@LINE+1]]:14: warning: 'Lambda' overrides 'ConditionalRun()' and registers a data callback with 'OnData()'; 'ConditionalRun()' never runs [fairmq-bugprone-ondata-with-conditionalrun]
bool Lambda::ConditionalRun() { return true; }
// Not reported: only one of the two.
struct OnlyCallback : fair::mq::Device
{
OnlyCallback() { OnData("data", &OnlyCallback::HandleData); }
bool HandleData(fair::mq::MessagePtr&, int) { return true; }
};
struct OnlyConditionalRun : fair::mq::Device
{
bool ConditionalRun() override { return true; }
};