clang-tools 8.0.0

OverloadedOperatorCheck.cpp
Go to the documentation of this file.
1 //===--- OverloadedOperatorCheck.cpp - clang-tidy--------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #include "OverloadedOperatorCheck.h"
11
12 using namespace clang::ast_matchers;
13
14 namespace clang {
15 namespace tidy {
16 namespace fuchsia {
17
18 namespace {
19 AST_MATCHER(FunctionDecl, isFuchsiaOverloadedOperator) {
20 if (const auto *CXXMethodNode = dyn_cast<CXXMethodDecl>(&Node)) {
21 if (CXXMethodNode->isCopyAssignmentOperator() ||
22 CXXMethodNode->isMoveAssignmentOperator())
23 return false;
24 if (CXXMethodNode->getParent()->isLambda())
25 return false;
26 }
27 return Node.isOverloadedOperator();
28 }
29 } // namespace
30
31 void OverloadedOperatorCheck::registerMatchers(MatchFinder *Finder) {
32 Finder->addMatcher(functionDecl(isFuchsiaOverloadedOperator()).bind("decl"),
33 this);
34 }
35
36 void OverloadedOperatorCheck::check(const MatchFinder::MatchResult &Result) {
37 const auto *D = Result.Nodes.getNodeAs<FunctionDecl>("decl");
38 assert(D && "No FunctionDecl captured!");
39
40 SourceLocation Loc = D->getBeginLoc();
41 if (Loc.isValid())
42 diag(Loc, "overloading %0 is disallowed") << D;
43 }
44
45 } // namespace fuchsia
46 } // namespace tidy
47 } // namespace clang
Loc
SourceLocation Loc
&#39;#&#39; location in the include directive
Definition: IncludeOrderCheck.cpp:37
clang::ast_matchers
Definition: AbseilMatcher.h:15
clang::tidy::matchers::AST_MATCHER
AST_MATCHER(BinaryOperator, isAssignmentOperator)
Definition: Matchers.h:20
OverloadedOperatorCheck.h
D
const Decl * D
Definition: XRefs.cpp:79
Result
llvm::Optional< llvm::Expected< tooling::AtomicChanges > > Result
Definition: ClangdServer.cpp:60
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ChangeNamespace.cpp:18