[win/asan] GetInstructionSize: Make `83 EC XX` a generic entry. (#119537)
[llvm-project.git] / clang-tools-extra / clang-tidy / fuchsia / VirtualInheritanceCheck.cpp
blob9c367423fdb534f2cc1771cb18ec1f2029958114
1 //===--- VirtualInheritanceCheck.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 "VirtualInheritanceCheck.h"
10 #include "clang/AST/ASTContext.h"
11 #include "clang/ASTMatchers/ASTMatchFinder.h"
13 using namespace clang::ast_matchers;
15 namespace clang::tidy::fuchsia {
17 namespace {
18 AST_MATCHER(CXXRecordDecl, hasDirectVirtualBaseClass) {
19 if (!Node.hasDefinition()) return false;
20 if (!Node.getNumVBases()) return false;
21 for (const CXXBaseSpecifier &Base : Node.bases())
22 if (Base.isVirtual()) return true;
23 return false;
25 } // namespace
27 void VirtualInheritanceCheck::registerMatchers(MatchFinder *Finder) {
28 // Defining classes using direct virtual inheritance is disallowed.
29 Finder->addMatcher(cxxRecordDecl(hasDirectVirtualBaseClass()).bind("decl"),
30 this);
33 void VirtualInheritanceCheck::check(const MatchFinder::MatchResult &Result) {
34 if (const auto *D = Result.Nodes.getNodeAs<CXXRecordDecl>("decl"))
35 diag(D->getBeginLoc(), "direct virtual inheritance is disallowed");
38 } // namespace clang::tidy::fuchsia