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 
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
SourceLocation Loc
&#39;#&#39; location in the include directive
AST_MATCHER(BinaryOperator, isAssignmentOperator)
Definition: Matchers.h:20
const Decl * D
Definition: XRefs.cpp:79
llvm::Optional< llvm::Expected< tooling::AtomicChanges > > Result
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//