MakeUniqueCheck.cpp 1.8 KB

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