clang-tools
22.0.0git
llvm-project
clang-tools-extra
clang-tidy
fuchsia
VirtualInheritanceCheck.cpp
Go to the documentation of this file.
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-exception
6
//
7
//===----------------------------------------------------------------------===//
8
9
#include "
VirtualInheritanceCheck.h
"
10
#include "clang/AST/ASTContext.h"
11
#include "clang/ASTMatchers/ASTMatchFinder.h"
12
13
using namespace
clang::ast_matchers
;
14
15
namespace
clang::tidy::fuchsia
{
16
17
namespace
{
18
AST_MATCHER
(CXXRecordDecl, hasDirectVirtualBaseClass) {
19
if
(!Node.hasDefinition())
20
return
false
;
21
if
(!Node.getNumVBases())
22
return
false
;
23
return
llvm::any_of(Node.bases(), [](
const
CXXBaseSpecifier &Base) {
24
return Base.isVirtual();
25
});
26
}
27
}
// namespace
28
29
void
VirtualInheritanceCheck::registerMatchers
(MatchFinder *Finder) {
30
// Defining classes using direct virtual inheritance is disallowed.
31
Finder->addMatcher(cxxRecordDecl(hasDirectVirtualBaseClass()).bind(
"decl"
),
32
this
);
33
}
34
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"
);
38
}
39
40
}
// namespace clang::tidy::fuchsia
VirtualInheritanceCheck.h
clang::tidy::fuchsia::VirtualInheritanceCheck::registerMatchers
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Definition
VirtualInheritanceCheck.cpp:29
clang::tidy::fuchsia::VirtualInheritanceCheck::check
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
Definition
VirtualInheritanceCheck.cpp:35
clang::ast_matchers
Definition
AbseilMatcher.h:16
clang::tidy::fuchsia
Definition
DefaultArgumentsCallsCheck.cpp:13
clang::tidy::matchers::AST_MATCHER
AST_MATCHER(BinaryOperator, isRelationalOperator)
Definition
clang-tidy/utils/Matchers.h:19
Generated on
for clang-tools by
1.14.0