clang-tools
22.0.0git
llvm-project
clang-tools-extra
clang-tidy
google
OverloadedUnaryAndCheck.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 "
OverloadedUnaryAndCheck.h
"
10
#include "clang/ASTMatchers/ASTMatchFinder.h"
11
#include "clang/ASTMatchers/ASTMatchers.h"
12
13
using namespace
clang::ast_matchers
;
14
15
namespace
clang::tidy::google::runtime
{
16
17
void
OverloadedUnaryAndCheck::registerMatchers
(
18
ast_matchers::MatchFinder *Finder) {
19
// Match unary methods that overload operator&.
20
Finder->addMatcher(
21
cxxMethodDecl(parameterCountIs(0), hasOverloadedOperatorName(
"&"
))
22
.bind(
"overload"
),
23
this
);
24
// Also match freestanding unary operator& overloads. Be careful not to match
25
// binary methods.
26
Finder->addMatcher(functionDecl(unless(cxxMethodDecl()), parameterCountIs(1),
27
hasOverloadedOperatorName(
"&"
))
28
.bind(
"overload"
),
29
this
);
30
}
31
32
void
OverloadedUnaryAndCheck::check
(
const
MatchFinder::MatchResult &Result) {
33
const
auto
*Decl = Result.Nodes.getNodeAs<FunctionDecl>(
"overload"
);
34
diag(Decl->getBeginLoc(),
35
"do not overload unary operator&, it is dangerous."
);
36
}
37
38
}
// namespace clang::tidy::google::runtime
OverloadedUnaryAndCheck.h
clang::tidy::google::runtime::OverloadedUnaryAndCheck::registerMatchers
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Definition
OverloadedUnaryAndCheck.cpp:17
clang::tidy::google::runtime::OverloadedUnaryAndCheck::check
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
Definition
OverloadedUnaryAndCheck.cpp:32
clang::ast_matchers
Definition
AbseilMatcher.h:13
clang::tidy::google::runtime
Definition
FloatTypesCheck.cpp:49
Generated on
for clang-tools by
1.14.0