brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.7 KiB · bf3173d Raw
46 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9#include "TemplateVirtualMemberFunctionCheck.h"10#include "clang/ASTMatchers/ASTMatchFinder.h"11 12using namespace clang::ast_matchers;13 14namespace clang::tidy::portability {15namespace {16AST_MATCHER(CXXMethodDecl, isUsed) { return Node.isUsed(); }17} // namespace18 19void TemplateVirtualMemberFunctionCheck::registerMatchers(MatchFinder *Finder) {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 31void TemplateVirtualMemberFunctionCheck::check(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::portability46