clang-tools 24.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 const auto WarningMessage =
23 cat("prefer absl::Cleanup's class template argument "
24 "deduction pattern in C++17 and higher");
25
26 return makeRule(
27 declStmt(hasSingleDecl(varDecl(
28 hasType(autoType()), hasTypeLoc(typeLoc().bind("auto_type_loc")),
29 hasInitializer(hasDescendant(
30 callExpr(callee(functionDecl(hasName("absl::MakeCleanup"))),
31 argumentCountIs(1))
32 .bind("make_cleanup_call")))))),
33 {changeTo(node("auto_type_loc"), cat("absl::Cleanup")),
34 changeTo(node("make_cleanup_call"), cat(callArgs("make_cleanup_call")))},
35 WarningMessage);
36}
37
40
41} // 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()