10#include "clang/ASTMatchers/ASTMatchFinder.h"
24 auto MethodMatcher = cxxMethodDecl(
25 parameterCountIs(1U), unless(isConst()), returns(voidType()),
26 hasParameter(0, hasType(qualType(hasCanonicalType(
27 qualType(unless(isConstQualified()),
28 references(namedDecl().bind(
"class"))))))),
29 ofClass(equalsBoundNode(
"class")));
34 auto FunctionMatcher = allOf(
35 unless(cxxMethodDecl()), parameterCountIs(2U), returns(voidType()),
37 0, hasType(qualType(hasCanonicalType(
38 qualType(unless(isConstQualified()), references(qualType()))
40 hasParameter(1, hasType(qualType(hasCanonicalType(
41 qualType(equalsBoundNode(
"type")))))));
42 Finder->addMatcher(functionDecl(unless(isDeleted()),
43 hasAnyName(
"swap",
"iter_swap"),
44 anyOf(MethodMatcher, FunctionMatcher))
50NoexceptSwapCheck::reportMissingNoexcept(
const FunctionDecl *
FuncDecl) {
51 return diag(
FuncDecl->getLocation(),
"swap functions should "
52 "be marked noexcept");
55void NoexceptSwapCheck::reportNoexceptEvaluatedToFalse(
56 const FunctionDecl *
FuncDecl,
const Expr *NoexceptExpr) {
57 diag(NoexceptExpr->getExprLoc(),
58 "noexcept specifier on swap function evaluates to 'false'");
DiagnosticBuilder diag(SourceLocation Loc, StringRef Description, DiagnosticIDs::Level Level=DiagnosticIDs::Warning)
Add a diagnostic with the check's name.
static constexpr const char FuncDecl[]