| 1 |
//===--- OverloadedOperatorCheck.cpp - clang-tidy--------------------------===// |
| 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 "OverloadedOperatorCheck.h" |
| 10 |
|
| 11 |
using namespace clang::ast_matchers; |
| 12 |
|
| 13 |
namespace clang::tidy::fuchsia { |
| 14 |
|
| 15 |
namespace { |
| 16 |
AST_MATCHER(FunctionDecl, isFuchsiaOverloadedOperator) { |
| 17 |
if (const auto *CXXMethodNode = dyn_cast<CXXMethodDecl>(&Node)) { |
| 18 |
if (CXXMethodNode->isCopyAssignmentOperator() || |
| 19 |
CXXMethodNode->isMoveAssignmentOperator()) |
| 20 |
return false; |
| 21 |
if (CXXMethodNode->getParent()->isLambda()) |
| 22 |
return false; |
| 23 |
} |
| 24 |
return Node.isOverloadedOperator(); |
| 25 |
} |
| 26 |
} // namespace |
| 27 |
|
| 28 |
void OverloadedOperatorCheck::registerMatchers(MatchFinder *Finder) { |
| 29 |
Finder->addMatcher(functionDecl(isFuchsiaOverloadedOperator()).bind("decl"), |
| 30 |
this); |
| 31 |
} |
| 32 |
|
| 33 |
void OverloadedOperatorCheck::check(const MatchFinder::MatchResult &Result) { |
| 34 |
const auto *D = Result.Nodes.getNodeAs<FunctionDecl>("decl"); |
| 35 |
assert(D && "No FunctionDecl captured!"); |
| 36 |
|
| 37 |
SourceLocation Loc = D->getBeginLoc(); |
| 38 |
if (Loc.isValid()) |
| 39 |
diag(Loc, "overloading %0 is disallowed") << D; |
| 40 |
} |
| 41 |
|
| 42 |
} // namespace clang::tidy::fuchsia |