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,
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
ast_matchers::internal::BindableMatcher< QualType > SmartPtrTypeMatcher
SmartPtrTypeMatcher getSmartPointerTypeMatcher() const override
Returns matcher that match with different smart pointer types.
static constexpr llvm::StringLiteral Name
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override
Returns whether the C++ version is compatible with current check.
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Base class for MakeSharedCheck and MakeUniqueCheck.