clang-tools 19.0.0git
MakeUniqueCheck.cpp
Go to the documentation of this file.
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
11using namespace clang::ast_matchers;
12
13namespace clang::tidy::modernize {
14
17 : MakeSmartPtrCheck(Name, Context, "std::make_unique"),
18 RequireCPlusPlus14(Options.get("MakeSmartPtrFunction", "").empty()) {}
19
22 return qualType(hasUnqualifiedDesugaredType(
23 recordType(hasDeclaration(classTemplateSpecializationDecl(
24 hasName("::std::unique_ptr"), templateArgumentCountIs(2),
25 hasTemplateArgument(
26 0, templateArgument(refersToType(qualType().bind(PointerType)))),
27 hasTemplateArgument(
28 1, templateArgument(refersToType(
29 qualType(hasDeclaration(classTemplateSpecializationDecl(
30 hasName("::std::default_delete"),
31 templateArgumentCountIs(1),
32 hasTemplateArgument(
33 0, templateArgument(refersToType(qualType(
34 equalsBoundNode(PointerType))))))))))))))));
35}
36
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
llvm::SmallString< 256U > Name
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Base class for MakeSharedCheck and MakeUniqueCheck.
ast_matchers::internal::BindableMatcher< QualType > SmartPtrTypeMatcher
MakeUniqueCheck(StringRef Name, ClangTidyContext *Context)
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override
Returns whether the C++ version is compatible with current check.
SmartPtrTypeMatcher getSmartPointerTypeMatcher() const override
Returns matcher that match with different smart pointer types.
static bool empty(SourceRange Range)