clang-tools 22.0.0git
CleanupCtadCheck.cpp
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "CleanupCtadCheck.h"
11#include "clang/ASTMatchers/ASTMatchers.h"
12#include "clang/Tooling/Transformer/RangeSelector.h"
13#include "clang/Tooling/Transformer/RewriteRule.h"
14#include "clang/Tooling/Transformer/Stencil.h"
15
16using namespace ::clang::ast_matchers;
17using namespace ::clang::transformer;
18
19namespace clang::tidy::abseil {
20
21static RewriteRuleWith<std::string> cleanupCtadCheckImpl() {
22 auto WarningMessage = cat("prefer absl::Cleanup's class template argument "
23 "deduction pattern in C++17 and higher");
24
25 return makeRule(
26 declStmt(hasSingleDecl(varDecl(
27 hasType(autoType()), hasTypeLoc(typeLoc().bind("auto_type_loc")),
28 hasInitializer(hasDescendant(
29 callExpr(callee(functionDecl(hasName("absl::MakeCleanup"))),
30 argumentCountIs(1))
31 .bind("make_cleanup_call")))))),
32 {changeTo(node("auto_type_loc"), cat("absl::Cleanup")),
33 changeTo(node("make_cleanup_call"), cat(callArgs("make_cleanup_call")))},
34 WarningMessage);
35}
36
39
40} // namespace clang::tidy::abseil
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
CleanupCtadCheck(StringRef Name, ClangTidyContext *Context)
TransformerClangTidyCheck(StringRef Name, ClangTidyContext *Context)
static RewriteRuleWith< std::string > cleanupCtadCheckImpl()