[TargetVersion] Only enable on RISC-V and AArch64 (#115991)
[llvm-project.git] / clang-tools-extra / clang-tidy / portability / TemplateVirtualMemberFunctionCheck.cpp
blob9c2f27f01f1849859e485de0770f82a007f188bb
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 //===----------------------------------------------------------------------===//
9 #include "TemplateVirtualMemberFunctionCheck.h"
10 #include "clang/ASTMatchers/ASTMatchFinder.h"
12 using namespace clang::ast_matchers;
14 namespace clang::tidy::portability {
15 namespace {
16 AST_MATCHER(CXXMethodDecl, isUsed) { return Node.isUsed(); }
17 } // namespace
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);
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