mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2026-11-25 13:11:36 +00:00
feat(tidy): add fairmq-bugprone-run-loop-ignores-state
- Report endless loops (while (true), for (;;), ...) in an override of Device::Run() that do not call NewStatePending() or WaitFor(). Such a device does not stop when a state change is requested. - Skip loops that call Send() or Receive(), which an interrupt stops, and loops with a break, return, throw or goto. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
55
test/tidy/fairmq-bugprone-run-loop-ignores-state.cxx
Normal file
55
test/tidy/fairmq-bugprone-run-loop-ignores-state.cxx
Normal file
@@ -0,0 +1,55 @@
|
||||
#include <fairmq/Device.h>
|
||||
|
||||
#include <thread>
|
||||
|
||||
struct Endless : fair::mq::Device
|
||||
{
|
||||
void Run() override
|
||||
{
|
||||
int n = 0;
|
||||
// CHECK-MESSAGES: :[[@LINE+1]]:9: warning: endless loop in 'Run()' does not check for a state change; the device does not stop on request; use 'while (!NewStatePending())' [fairmq-bugprone-run-loop-ignores-state]
|
||||
while (true) {
|
||||
++n;
|
||||
}
|
||||
// CHECK-MESSAGES: :[[@LINE+1]]:9: warning: endless loop in 'Run()' does not check for a state change; the device does not stop on request; use 'while (!NewStatePending())' [fairmq-bugprone-run-loop-ignores-state]
|
||||
for (;;) {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Not reported: the loops look at the state, transfer data or end.
|
||||
struct Fine : fair::mq::Device
|
||||
{
|
||||
void Run() override
|
||||
{
|
||||
while (!NewStatePending()) {
|
||||
}
|
||||
while (true) {
|
||||
if (NewStatePending()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (;;) {
|
||||
if (!WaitFor(std::chrono::seconds(1))) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
while (1) {
|
||||
auto msg(NewMessage());
|
||||
Send(msg, "data");
|
||||
}
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Not reported: not Run() of a device.
|
||||
struct Other
|
||||
{
|
||||
void Run()
|
||||
{
|
||||
while (true) {
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user