clang-tools 20.0.0git
TemplateVirtualMemberFunctionCheck.cpp
Go to the documentation of this file.
1//===--- TemplateVirtualMemberFunctionCheck.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
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(ofClass(classTemplateSpecializationDecl(
22 unless(isExplicitTemplateSpecialization()))
23 .bind("specialization")),
24 isVirtual(), unless(isUsed()),
25 unless(cxxDestructorDecl(isDefaulted())))
26 .bind("method"),
27 this);
28}
29
31 const MatchFinder::MatchResult &Result) {
32 const auto *ImplicitSpecialization =
33 Result.Nodes.getNodeAs<ClassTemplateSpecializationDecl>("specialization");
34 const auto *MethodDecl = Result.Nodes.getNodeAs<CXXMethodDecl>("method");
35
36 diag(MethodDecl->getLocation(),
37 "unspecified virtual member function instantiation; the virtual "
38 "member function is not instantiated but it might be with a "
39 "different compiler");
40 diag(ImplicitSpecialization->getPointOfInstantiation(),
41 "template instantiated here", DiagnosticIDs::Note);
42}
43
44} // namespace clang::tidy::portability
::clang::DynTypedNode Node
DiagnosticBuilder diag(SourceLocation Loc, StringRef Description, DiagnosticIDs::Level Level=DiagnosticIDs::Warning)
Add a diagnostic with the check's name.
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.