10#include "../utils/Matchers.h"
11#include "clang/ASTMatchers/ASTMatchFinder.h"
12#include "clang/ASTMatchers/ASTMatchers.h"
21 hasReturnValue(declRefExpr(to(parmVarDecl(hasType(hasCanonicalType(
22 qualType(matchers::isReferenceToConst()).bind(
"type"))))))),
23 hasAncestor(functionDecl(hasReturnTypeLoc(
24 loc(qualType(hasCanonicalType(equalsBoundNode(
"type"))))))))
30 const MatchFinder::MatchResult &Result) {
31 const auto *R = Result.Nodes.getNodeAs<ReturnStmt>(
"ret");
32 const SourceRange
Range = R->getRetValue()->getSourceRange();
33 if (
Range.isInvalid())
36 "returning a constant reference parameter may cause use-after-free "
37 "when the parameter is constructed from a temporary")
CharSourceRange Range
SourceRange for the file name.
DiagnosticBuilder diag(SourceLocation Loc, StringRef Description, DiagnosticIDs::Level Level=DiagnosticIDs::Warning)
Add a diagnostic with the check's name.
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.