1 //===--- TemplateVirtualMemberFunctionCheck.cpp - clang-tidy --------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "TemplateVirtualMemberFunctionCheck.h"
10 #include "clang/ASTMatchers/ASTMatchFinder.h"
12 using namespace clang::ast_matchers
;
14 namespace clang::tidy::portability
{
16 AST_MATCHER(CXXMethodDecl
, isUsed
) { return Node
.isUsed(); }
19 void TemplateVirtualMemberFunctionCheck::registerMatchers(MatchFinder
*Finder
) {
21 cxxMethodDecl(ofClass(classTemplateSpecializationDecl(
22 unless(isExplicitTemplateSpecialization()))
23 .bind("specialization")),
24 isVirtual(), unless(isUsed()),
25 unless(cxxDestructorDecl(isDefaulted())))
30 void TemplateVirtualMemberFunctionCheck::check(
31 const MatchFinder::MatchResult
&Result
) {
32 const auto *ImplicitSpecialization
=
33 Result
.Nodes
.getNodeAs
<ClassTemplateSpecializationDecl
>("specialization");
34 const auto *MethodDecl
= Result
.Nodes
.getNodeAs
<CXXMethodDecl
>("method");
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
);
44 } // namespace clang::tidy::portability