clang-tools 19.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
19using namespace ::clang::ast_matchers;
20using namespace ::clang::transformer;
21
22namespace clang::tidy::abseil {
23
24RewriteRuleWith<std::string> CleanupCtadCheckImpl() {
25 auto warning_message = cat("prefer absl::Cleanup's class template argument "
26 "deduction pattern in C++17 and higher");
27
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);
38}
39
41 : utils::TransformerClangTidyCheck(CleanupCtadCheckImpl(), Name, Context) {}
42
43} // namespace clang::tidy::abseil
llvm::SmallString< 256U > Name
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
CleanupCtadCheck(StringRef Name, ClangTidyContext *Context)
RewriteRuleWith< std::string > CleanupCtadCheckImpl()