Files
FairMQ/fairmq/tidy/Transfer.h
Claude 3b3446bfcb 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>
2026-11-10 09:29:18 +00:00

46 lines
1.8 KiB
C++

/********************************************************************************
* Copyright (C) 2026 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* *
* This software is distributed under the terms of the *
* GNU Lesser General Public Licence (LGPL) version 3, *
* copied verbatim in the file "LICENSE" *
********************************************************************************/
#ifndef FAIR_MQ_TIDY_TRANSFER_H
#define FAIR_MQ_TIDY_TRANSFER_H
#include <clang/AST/ASTContext.h>
#include <clang/AST/Expr.h>
#include <clang/ASTMatchers/ASTMatchers.h>
#include <string>
namespace fair::mq::tidy {
/// Matches `fair::mq::Device`, `fair::mq::Channel`, `fair::mq::Socket` and
/// classes derived from them, i.e. the classes with `Send()` and `Receive()`.
inline auto transferClass()
{
using namespace clang::ast_matchers;
return cxxRecordDecl(anyOf(isSameOrDerivedFrom("::fair::mq::Device"),
isSameOrDerivedFrom("::fair::mq::Channel"),
isSameOrDerivedFrom("::fair::mq::Socket")));
}
/// Matches a call of `Send()` or `Receive()` (as given) of a transfer class.
inline auto transferCall(std::string const& name)
{
using namespace clang::ast_matchers;
return cxxMemberCallExpr(callee(cxxMethodDecl(hasName(name), ofClass(transferClass()))));
}
/// True if the value of `e` is discarded: `e` is an expression statement or
/// the increment of a for loop. A cast to void does not count, because it
/// discards the value on purpose.
bool isDiscarded(clang::Expr const& e, clang::ASTContext& ctx);
} // namespace fair::mq::tidy
#endif /* FAIR_MQ_TIDY_TRANSFER_H */