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
;
13 namespace clang::tidy::modernize
{
15 MakeUniqueCheck::MakeUniqueCheck(StringRef Name
,
16 clang::tidy::ClangTidyContext
*Context
)
17 : MakeSmartPtrCheck(Name
, Context
, "std::make_unique"),
18 RequireCPlusPlus14(Options
.get("MakeSmartPtrFunction", "").empty()) {}
20 MakeUniqueCheck::SmartPtrTypeMatcher
21 MakeUniqueCheck::getSmartPointerTypeMatcher() const {
22 return qualType(hasUnqualifiedDesugaredType(
23 recordType(hasDeclaration(classTemplateSpecializationDecl(
24 hasName("::std::unique_ptr"), templateArgumentCountIs(2),
26 0, templateArgument(refersToType(qualType().bind(PointerType
)))),
28 1, templateArgument(refersToType(
29 qualType(hasDeclaration(classTemplateSpecializationDecl(
30 hasName("::std::default_delete"),
31 templateArgumentCountIs(1),
33 0, templateArgument(refersToType(qualType(
34 equalsBoundNode(PointerType
))))))))))))))));
37 bool MakeUniqueCheck::isLanguageVersionSupported(
38 const LangOptions
&LangOpts
) const {
39 return RequireCPlusPlus14
? LangOpts
.CPlusPlus14
: LangOpts
.CPlusPlus11
;
42 // FixItHint is done by MakeSmartPtrCheck
44 } // namespace clang::tidy::modernize