2017-12-23 00:52:25 +08:00
|
|
|
//===--- OverloadedOperatorCheck.cpp - clang-tidy--------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "OverloadedOperatorCheck.h"
|
|
|
|
|
|
|
|
using namespace clang::ast_matchers;
|
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
namespace tidy {
|
|
|
|
namespace fuchsia {
|
|
|
|
|
2018-02-19 03:02:35 +08:00
|
|
|
namespace {
|
2017-12-23 00:52:25 +08:00
|
|
|
AST_MATCHER(FunctionDecl, isFuchsiaOverloadedOperator) {
|
|
|
|
if (const auto *CXXMethodNode = dyn_cast<CXXMethodDecl>(&Node)) {
|
|
|
|
if (CXXMethodNode->isCopyAssignmentOperator() ||
|
|
|
|
CXXMethodNode->isMoveAssignmentOperator())
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return Node.isOverloadedOperator();
|
|
|
|
}
|
2018-02-19 03:02:35 +08:00
|
|
|
} // namespace
|
2017-12-23 00:52:25 +08:00
|
|
|
|
|
|
|
void OverloadedOperatorCheck::registerMatchers(MatchFinder *Finder) {
|
|
|
|
Finder->addMatcher(functionDecl(isFuchsiaOverloadedOperator()).bind("decl"),
|
|
|
|
this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OverloadedOperatorCheck::check(const MatchFinder::MatchResult &Result) {
|
2018-01-04 06:10:11 +08:00
|
|
|
const auto *D = Result.Nodes.getNodeAs<FunctionDecl>("decl");
|
|
|
|
assert(D && "No FunctionDecl captured!");
|
2018-08-10 06:42:26 +08:00
|
|
|
|
|
|
|
SourceLocation Loc = D->getBeginLoc();
|
2018-01-04 06:10:11 +08:00
|
|
|
if (Loc.isValid())
|
2018-01-18 01:41:50 +08:00
|
|
|
diag(Loc, "overloading %0 is disallowed") << D;
|
2017-12-23 00:52:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace fuchsia
|
|
|
|
} // namespace tidy
|
|
|
|
} // namespace clang
|