[mlir][ods] Add cppClassName to ConfinedType
[llvm-project.git] / clang-tools-extra / clang-tidy / fuchsia / VirtualInheritanceCheck.cpp
blob54a4d73c3fffcd8df42a9960d6a4c36d4c8e8995
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 {
16 namespace tidy {
17 namespace fuchsia {
19 namespace {
20 AST_MATCHER(CXXRecordDecl, hasDirectVirtualBaseClass) {
21 if (!Node.hasDefinition()) return false;
22 if (!Node.getNumVBases()) return false;
23 for (const CXXBaseSpecifier &Base : Node.bases())
24 if (Base.isVirtual()) return true;
25 return false;
27 } // namespace
29 void VirtualInheritanceCheck::registerMatchers(MatchFinder *Finder) {
30 // Defining classes using direct virtual inheritance is disallowed.
31 Finder->addMatcher(cxxRecordDecl(hasDirectVirtualBaseClass()).bind("decl"),
32 this);
35 void VirtualInheritanceCheck::check(const MatchFinder::MatchResult &Result) {
36 if (const auto *D = Result.Nodes.getNodeAs<CXXRecordDecl>("decl"))
37 diag(D->getBeginLoc(), "direct virtual inheritance is disallowed");
40 } // namespace fuchsia
41 } // namespace tidy
42 } // namespace clang