clang-tools  15.0.0git
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,
19  : MakeSmartPtrCheck(Name, Context, "std::make_unique"),
20  RequireCPlusPlus14(Options.get("MakeSmartPtrFunction", "").empty()) {}
21 
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 
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::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition: ClangTidyDiagnosticConsumer.h:67
clang::tidy::modernize::MakeUniqueCheck::getSmartPointerTypeMatcher
SmartPtrTypeMatcher getSmartPointerTypeMatcher() const override
Returns matcher that match with different smart pointer types.
Definition: MakeUniqueCheck.cpp:23
Name
Token Name
Definition: MacroToEnumCheck.cpp:89
clang::tidy::modernize::MakeSmartPtrCheck
Base class for MakeSharedCheck and MakeUniqueCheck.
Definition: MakeSmartPtrCheck.h:24
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ApplyReplacements.h:27
clang::tidy::modernize::empty
static bool empty(SourceRange Range)
Definition: MacroToEnumCheck.cpp:538
LangOpts
const LangOptions * LangOpts
Definition: ExtractFunction.cpp:366
clang::tidy::modernize::MakeSmartPtrCheck::SmartPtrTypeMatcher
ast_matchers::internal::BindableMatcher< QualType > SmartPtrTypeMatcher
Definition: MakeSmartPtrCheck.h:35
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
MakeUniqueCheck.h