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