clang-tools 22.0.0git
TemplateVirtualMemberFunctionCheck.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
10#include "clang/ASTMatchers/ASTMatchFinder.h"
11
12using namespace clang::ast_matchers;
13
15namespace {
16AST_MATCHER(CXXMethodDecl, isUsed) { return Node.isUsed(); }
17} // namespace
18
20 Finder->addMatcher(
21 cxxMethodDecl(isVirtual(),
22 ofClass(classTemplateSpecializationDecl(
23 unless(isExplicitTemplateSpecialization()))
24 .bind("specialization")),
25 unless(isUsed()), unless(isPure()),
26 unless(cxxDestructorDecl(isDefaulted())))
27 .bind("method"),
28 this);
29}
30
32 const MatchFinder::MatchResult &Result) {
33 const auto *ImplicitSpecialization =
34 Result.Nodes.getNodeAs<ClassTemplateSpecializationDecl>("specialization");
35 const auto *MethodDecl = Result.Nodes.getNodeAs<CXXMethodDecl>("method");
36
37 diag(MethodDecl->getLocation(),
38 "unspecified virtual member function instantiation; the virtual "
39 "member function is not instantiated but it might be with a "
40 "different compiler");
41 diag(ImplicitSpecialization->getPointOfInstantiation(),
42 "template instantiated here", DiagnosticIDs::Note);
43}
44
45} // namespace clang::tidy::portability
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
AST_MATCHER(BinaryOperator, isRelationalOperator)