1 //===--- MakeUniqueCheck.cpp - clang-tidy----------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "MakeUniqueCheck.h"
11 using namespace clang::ast_matchers
;
17 MakeUniqueCheck::MakeUniqueCheck(StringRef Name
,
18 clang::tidy::ClangTidyContext
*Context
)
19 : MakeSmartPtrCheck(Name
, Context
, "std::make_unique"),
20 RequireCPlusPlus14(Options
.get("MakeSmartPtrFunction", "").empty()) {}
22 MakeUniqueCheck::SmartPtrTypeMatcher
23 MakeUniqueCheck::getSmartPointerTypeMatcher() const {
24 return qualType(hasUnqualifiedDesugaredType(
25 recordType(hasDeclaration(classTemplateSpecializationDecl(
26 hasName("::std::unique_ptr"), templateArgumentCountIs(2),
28 0, templateArgument(refersToType(qualType().bind(PointerType
)))),
30 1, templateArgument(refersToType(
31 qualType(hasDeclaration(classTemplateSpecializationDecl(
32 hasName("::std::default_delete"),
33 templateArgumentCountIs(1),
35 0, templateArgument(refersToType(qualType(
36 equalsBoundNode(PointerType
))))))))))))))));
39 bool MakeUniqueCheck::isLanguageVersionSupported(
40 const LangOptions
&LangOpts
) const {
41 return RequireCPlusPlus14
? LangOpts
.CPlusPlus14
: LangOpts
.CPlusPlus11
;
44 // FixItHint is done by MakeSmartPtrCheck
46 } // namespace modernize