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 9 #include "TemplateVirtualMemberFunctionCheck.h" 10 #include "clang/ASTMatchers/ASTMatchFinder.h" 11 12 using namespace clang::ast_matchers; 13 14 namespace clang::tidy::portability { 15 namespace { 16 AST_MATCHER(CXXMethodDecl, isUsed) { return Node.isUsed(); } 17 } // namespace 18 19 void TemplateVirtualMemberFunctionCheck::registerMatchers(MatchFinder *Finder) { 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 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"); 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 45