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
MakeUniqueCheck(StringRef Name,clang::tidy::ClangTidyContext * Context)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
getSmartPointerTypeMatcher() const23 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
isLanguageVersionSupported(const LangOptions & LangOpts) const39 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
49