clang-tools
20.0.0git
llvm-project
clang-tools-extra
clang-tidy
abseil
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::tidy::abseil
{
23
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"
);
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
40
CleanupCtadCheck::CleanupCtadCheck
(StringRef
Name
,
ClangTidyContext
*Context)
41
: utils::TransformerClangTidyCheck(
CleanupCtadCheckImpl
(),
Name
, Context) {}
42
43
}
// namespace clang::tidy::abseil
Name
llvm::SmallString< 256U > Name
Definition:
ChainedComparisonCheck.cpp:42
CleanupCtadCheck.h
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition:
ClangTidyDiagnosticConsumer.h:69
clang::tidy::abseil::CleanupCtadCheck::CleanupCtadCheck
CleanupCtadCheck(StringRef Name, ClangTidyContext *Context)
Definition:
CleanupCtadCheck.cpp:40
clang::ast_matchers
Definition:
AbseilMatcher.h:13
clang::tidy::abseil
Definition:
AbseilTidyModule.cpp:33
clang::tidy::abseil::CleanupCtadCheckImpl
RewriteRuleWith< std::string > CleanupCtadCheckImpl()
Definition:
CleanupCtadCheck.cpp:24
Generated on Sat Nov 23 2024 23:50:00 for clang-tools by
1.9.6