clang-tools  14.0.0git
CleanupCtadCheck.cpp
Go to the documentation of this file.
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 //===----------------------------------------------------------------------===//
8 
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"
18 
19 using namespace ::clang::ast_matchers;
20 using namespace ::clang::transformer;
21 
22 namespace clang {
23 namespace tidy {
24 namespace abseil {
25 
26 RewriteRule CleanupCtadCheckImpl() {
27  auto warning_message = cat("prefer absl::Cleanup's class template argument "
28  "deduction pattern in C++17 and higher");
29 
30  return makeRule(
31  declStmt(hasSingleDecl(varDecl(
32  hasType(autoType()), hasTypeLoc(typeLoc().bind("auto_type_loc")),
33  hasInitializer(hasDescendant(
34  callExpr(callee(functionDecl(hasName("absl::MakeCleanup"))),
35  argumentCountIs(1))
36  .bind("make_cleanup_call")))))),
37  {changeTo(node("auto_type_loc"), cat("absl::Cleanup")),
38  changeTo(node("make_cleanup_call"), cat(callArgs("make_cleanup_call")))},
39  warning_message);
40 }
41 
43  : utils::TransformerClangTidyCheck(CleanupCtadCheckImpl(), Name, Context) {}
44 
45 } // namespace abseil
46 } // namespace tidy
47 } // namespace clang
CleanupCtadCheck.h
clang::ast_matchers
Definition: AbseilMatcher.h:14
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition: ClangTidyDiagnosticConsumer.h:73
Name
static constexpr llvm::StringLiteral Name
Definition: UppercaseLiteralSuffixCheck.cpp:28
CompletionModelCodegen.node
def node(n, label, next_label)
Definition: CompletionModelCodegen.py:70
clang::tidy::abseil::CleanupCtadCheck::CleanupCtadCheck
CleanupCtadCheck(StringRef Name, ClangTidyContext *Context)
Definition: CleanupCtadCheck.cpp:42
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ApplyReplacements.h:27
clang::tidy::abseil::CleanupCtadCheckImpl
RewriteRule CleanupCtadCheckImpl()
Definition: CleanupCtadCheck.cpp:26