mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2026-11-25 13:11:36 +00:00
feat(tidy): add fairmq-bugprone-unchecked-transfer-result
- Report Receive() calls whose result is discarded. On a timeout, an error or an interrupt the message stays empty, and only the result tells. - Report Send() too with the option CheckSend: true. Off by default, because many devices ignore the result of Send() on purpose. - A cast to void discards the result on purpose and is not reported. - Add Transfer.h with matchers for Send() and Receive() of Device, Channel and Socket, and isDiscarded(), for this and later checks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
26
test/tidy/fairmq-bugprone-unchecked-transfer-result.cxx
Normal file
26
test/tidy/fairmq-bugprone-unchecked-transfer-result.cxx
Normal file
@@ -0,0 +1,26 @@
|
||||
// TIDY-CONFIG: {CheckOptions: {fairmq-bugprone-unchecked-transfer-result.CheckSend: true}}
|
||||
#include <fairmq/Device.h>
|
||||
|
||||
struct Processor : fair::mq::Device
|
||||
{
|
||||
bool ConditionalRun() override
|
||||
{
|
||||
auto msg(NewMessage());
|
||||
// CHECK-MESSAGES: :[[@LINE+1]]:9: warning: result of 'Receive()' is not checked; it is negative on a timeout, an error or an interrupt [fairmq-bugprone-unchecked-transfer-result]
|
||||
Receive(msg, "in");
|
||||
// CHECK-MESSAGES: :[[@LINE+1]]:29: warning: result of 'Receive()' is not checked; it is negative on a timeout, an error or an interrupt [fairmq-bugprone-unchecked-transfer-result]
|
||||
GetChannel("in", 0).Receive(msg);
|
||||
for (int i = 0; i < 3; ++i)
|
||||
// CHECK-MESSAGES: :[[@LINE+1]]:13: warning: result of 'Send()' is not checked; it is negative on a timeout, an error or an interrupt [fairmq-bugprone-unchecked-transfer-result]
|
||||
Send(msg, "out");
|
||||
|
||||
// Not reported: the result is used, or discarded on purpose.
|
||||
if (Receive(msg, "in") < 0) {
|
||||
return false;
|
||||
}
|
||||
auto const bytes = Send(msg, "out");
|
||||
static_cast<void>(Send(msg, "out"));
|
||||
(void)Receive(msg, "in");
|
||||
return bytes >= 0;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user