clang-tools 10.0.0

MakeUniqueCheck.cpp
Go to the documentation of this file.
1 //===--- MakeUniqueCheck.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 "MakeUniqueCheck.h"
10
11 using namespace clang::ast_matchers;
12
13 namespace clang {
14 namespace tidy {
15 namespace modernize {
16
17 MakeUniqueCheck::MakeUniqueCheck(StringRef Name,
18 clang::tidy::ClangTidyContext *Context)
19 : MakeSmartPtrCheck(Name, Context, "std::make_unique"),
20 RequireCPlusPlus14(Options.get("MakeSmartPtrFunction", "").empty()) {}
21
22 MakeUniqueCheck::SmartPtrTypeMatcher
23 MakeUniqueCheck::getSmartPointerTypeMatcher() const {
24 return qualType(hasUnqualifiedDesugaredType(
25 recordType(hasDeclaration(classTemplateSpecializationDecl(
26 hasName("::std::unique_ptr"), templateArgumentCountIs(2),
27 hasTemplateArgument(
28 0, templateArgument(refersToType(qualType().bind(PointerType)))),
29 hasTemplateArgument(
30 1, templateArgument(refersToType(
31 qualType(hasDeclaration(classTemplateSpecializationDecl(
32 hasName("::std::default_delete"),
33 templateArgumentCountIs(1),
34 hasTemplateArgument(
35 0, templateArgument(refersToType(qualType(
36 equalsBoundNode(PointerType))))))))))))))));
37 }
38
39 bool MakeUniqueCheck::isLanguageVersionSupported(
40 const LangOptions &LangOpts) const {
41 return RequireCPlusPlus14 ? LangOpts.CPlusPlus14 : LangOpts.CPlusPlus11;
42 }
43
44 // FixItHint is done by MakeSmartPtrCheck
45
46 } // namespace modernize
47 } // namespace tidy
48 } // namespace clang
clang::ast_matchers
Definition: AbseilMatcher.h:14
clang::tidy::modernize::MakeSmartPtrCheck::SmartPtrTypeMatcher
ast_matchers::internal::BindableMatcher< QualType > SmartPtrTypeMatcher
Definition: MakeSmartPtrCheck.h:35
clang::tidy::modernize::MakeUniqueCheck::getSmartPointerTypeMatcher
SmartPtrTypeMatcher getSmartPointerTypeMatcher() const override
Returns matcher that match with different smart pointer types.
Definition: MakeUniqueCheck.cpp:23
Name
static constexpr llvm::StringLiteral Name
Definition: UppercaseLiteralSuffixCheck.cpp:27
clang::tidy::modernize::MakeSmartPtrCheck::PointerType
static const char PointerType[]
Definition: MakeSmartPtrCheck.h:46
clang::tidy::modernize::MakeUniqueCheck::isLanguageVersionSupported
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override
Returns whether the C++ version is compatible with current check.
Definition: MakeUniqueCheck.cpp:39
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ApplyReplacements.h:27
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition: ClangTidyDiagnosticConsumer.h:77
MakeUniqueCheck.h
clang::tidy::modernize::MakeSmartPtrCheck
Base class for MakeSharedCheck and MakeUniqueCheck.
Definition: MakeSmartPtrCheck.h:24