clang-tools 8.0.0

MakeUniqueCheck.cpp
Go to the documentation of this file.
1 //===--- MakeUniqueCheck.cpp - clang-tidy----------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #include "MakeUniqueCheck.h"
11
12 using namespace clang::ast_matchers;
13
14 namespace clang {
15 namespace tidy {
16 namespace modernize {
17
18 MakeUniqueCheck::MakeUniqueCheck(StringRef Name,
19 clang::tidy::ClangTidyContext *Context)
20 : MakeSmartPtrCheck(Name, Context, "std::make_unique"),
21 RequireCPlusPlus14(Options.get("MakeSmartPtrFunction", "").empty()) {}
22
23 MakeUniqueCheck::SmartPtrTypeMatcher
24 MakeUniqueCheck::getSmartPointerTypeMatcher() const {
25 return qualType(hasUnqualifiedDesugaredType(
26 recordType(hasDeclaration(classTemplateSpecializationDecl(
27 hasName("::std::unique_ptr"), templateArgumentCountIs(2),
28 hasTemplateArgument(
29 0, templateArgument(refersToType(qualType().bind(PointerType)))),
30 hasTemplateArgument(
31 1, templateArgument(refersToType(
32 qualType(hasDeclaration(classTemplateSpecializationDecl(
33 hasName("::std::default_delete"),
34 templateArgumentCountIs(1),
35 hasTemplateArgument(
36 0, templateArgument(refersToType(qualType(
37 equalsBoundNode(PointerType))))))))))))))));
38 }
39
40 bool MakeUniqueCheck::isLanguageVersionSupported(
41 const LangOptions &LangOpts) const {
42 return RequireCPlusPlus14 ? LangOpts.CPlusPlus14 : LangOpts.CPlusPlus11;
43 }
44
45 } // namespace modernize
46 } // namespace tidy
47 } // namespace clang
clang::ast_matchers
Definition: AbseilMatcher.h:15
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:24
Name
static constexpr llvm::StringLiteral Name
Definition: UppercaseLiteralSuffixCheck.cpp:28
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:40
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ChangeNamespace.cpp:18
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition: ClangTidyDiagnosticConsumer.h:100
MakeUniqueCheck.h
clang::tidy::modernize::MakeSmartPtrCheck
Base class for MakeSharedCheck and MakeUniqueCheck.
Definition: MakeSmartPtrCheck.h:25