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   }
25   return Node.isOverloadedOperator();
26 }
27 } // namespace
28 
29 void OverloadedOperatorCheck::registerMatchers(MatchFinder *Finder) {
30   Finder->addMatcher(functionDecl(isFuchsiaOverloadedOperator()).bind("decl"),
31                      this);
32 }
33 
34 void OverloadedOperatorCheck::check(const MatchFinder::MatchResult &Result) {
35   const auto *D = Result.Nodes.getNodeAs<FunctionDecl>("decl");
36   assert(D && "No FunctionDecl captured!");
37 
38   SourceLocation Loc = D->getLocStart();
39   if (Loc.isValid())
40     diag(Loc, "overloading %0 is disallowed") << D;
41 }
42 
43 } // namespace fuchsia
44 } // namespace tidy
45 } // namespace clang
46