[clang][modules] Don't prevent translation of FW_Private includes when explicitly...
[llvm-project.git] / clang-tools-extra / clang-tidy / abseil / CleanupCtadCheck.cpp
blob06f98c76269b5963c62c3b042d8f501e1098773c
1 //===--- CleanupCtadCheck.cpp - clang-tidy --------------------------------===//
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 //===----------------------------------------------------------------------===//
9 #include "CleanupCtadCheck.h"
10 #include "../utils/TransformerClangTidyCheck.h"
11 #include "clang/AST/ASTContext.h"
12 #include "clang/ASTMatchers/ASTMatchFinder.h"
13 #include "clang/ASTMatchers/ASTMatchers.h"
14 #include "clang/Tooling/Transformer/RangeSelector.h"
15 #include "clang/Tooling/Transformer/RewriteRule.h"
16 #include "clang/Tooling/Transformer/Stencil.h"
17 #include "llvm/ADT/StringRef.h"
19 using namespace ::clang::ast_matchers;
20 using namespace ::clang::transformer;
22 namespace clang::tidy::abseil {
24 RewriteRuleWith<std::string> CleanupCtadCheckImpl() {
25 auto warning_message = cat("prefer absl::Cleanup's class template argument "
26 "deduction pattern in C++17 and higher");
28 return makeRule(
29 declStmt(hasSingleDecl(varDecl(
30 hasType(autoType()), hasTypeLoc(typeLoc().bind("auto_type_loc")),
31 hasInitializer(hasDescendant(
32 callExpr(callee(functionDecl(hasName("absl::MakeCleanup"))),
33 argumentCountIs(1))
34 .bind("make_cleanup_call")))))),
35 {changeTo(node("auto_type_loc"), cat("absl::Cleanup")),
36 changeTo(node("make_cleanup_call"), cat(callArgs("make_cleanup_call")))},
37 warning_message);
40 CleanupCtadCheck::CleanupCtadCheck(StringRef Name, ClangTidyContext *Context)
41 : utils::TransformerClangTidyCheck(CleanupCtadCheckImpl(), Name, Context) {}
43 } // namespace clang::tidy::abseil