clang-tools 23.0.0git
MakeUniqueCheck.cpp
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
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
11using namespace clang::ast_matchers;
12
13namespace clang::tidy::modernize {
14
16 : MakeSmartPtrCheck(Name, Context, "std::make_unique"),
17 RequireCPlusPlus14(Options.get("MakeSmartPtrFunction", "").empty()) {}
18
21 return qualType(hasUnqualifiedDesugaredType(
22 recordType(hasDeclaration(classTemplateSpecializationDecl(
23 hasName("::std::unique_ptr"), templateArgumentCountIs(2),
24 hasTemplateArgument(
25 0, templateArgument(refersToType(qualType().bind(PointerType)))),
26 hasTemplateArgument(
27 1, templateArgument(refersToType(
28 qualType(hasDeclaration(classTemplateSpecializationDecl(
29 hasName("::std::default_delete"),
30 templateArgumentCountIs(1),
31 hasTemplateArgument(
32 0, templateArgument(refersToType(qualType(
33 equalsBoundNode(PointerType))))))))))))))));
34}
35
37 const LangOptions &LangOpts) const {
38 return RequireCPlusPlus14 ? LangOpts.CPlusPlus14 : LangOpts.CPlusPlus11;
39}
40
41// FixItHint is done by MakeSmartPtrCheck
42
43} // namespace clang::tidy::modernize
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
MakeSmartPtrCheck(StringRef Name, ClangTidyContext *Context, StringRef MakeSmartPtrFunctionName)
ast_matchers::internal::BindableMatcher< QualType > SmartPtrTypeMatcher
MakeUniqueCheck(StringRef Name, ClangTidyContext *Context)
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override
SmartPtrTypeMatcher getSmartPointerTypeMatcher() const override
Returns matcher that match with different smart pointer types.
static bool empty(SourceRange Range)