aboutsummaryrefslogtreecommitdiff
path: root/clang-tools-extra/clang-tidy/bugprone/UniquePtrArrayMismatchCheck.cpp
blob: 8d09b4b320c2cb5ec88c7b04435079d63256fa92 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
//===--- UniquePtrArrayMismatchCheck.cpp - clang-tidy ---------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "UniquePtrArrayMismatchCheck.h"

using namespace clang::ast_matchers;

namespace clang::tidy::bugprone {

UniquePtrArrayMismatchCheck::UniquePtrArrayMismatchCheck(
    StringRef Name, ClangTidyContext *Context)
    : SmartPtrArrayMismatchCheck(Name, Context, "unique") {}

UniquePtrArrayMismatchCheck::SmartPtrClassMatcher
UniquePtrArrayMismatchCheck::getSmartPointerClassMatcher() const {
  auto DeleterDecl = classTemplateSpecializationDecl(
      hasName("::std::default_delete"), templateArgumentCountIs(1),
      hasTemplateArgument(0, templateArgument(refersToType(
                                 qualType(equalsBoundNode(PointerTypeN))))));
  return classTemplateSpecializationDecl(
      hasName("::std::unique_ptr"), templateArgumentCountIs(2),
      hasTemplateArgument(
          0, templateArgument(refersToType(qualType().bind(PointerTypeN)))),
      hasTemplateArgument(1, templateArgument(refersToType(
                                 qualType(hasDeclaration(DeleterDecl))))));
}

} // namespace clang::tidy::bugprone