clang-tools 6.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 AST_MATCHER(FunctionDecl, isFuchsiaOverloadedOperator) {
19 if (const auto *CXXMethodNode = dyn_cast<CXXMethodDecl>(&Node)) {
20 if (CXXMethodNode->isCopyAssignmentOperator() ||
21 CXXMethodNode->isMoveAssignmentOperator())
22 return false;
23 }
24 return Node.isOverloadedOperator();
25 }
26
27 void OverloadedOperatorCheck::registerMatchers(MatchFinder *Finder) {
28 Finder->addMatcher(functionDecl(isFuchsiaOverloadedOperator()).bind("decl"),
29 this);
30 }
31
32 void OverloadedOperatorCheck::check(const MatchFinder::MatchResult &Result) {
33 const auto *D = Result.Nodes.getNodeAs<FunctionDecl>("decl");
34 assert(D && "No FunctionDecl captured!");
35
36 SourceLocation Loc = D->getLocStart();
37 if (Loc.isValid())
38 diag(Loc, "cannot overload %0") << D;
39 }
40
41 } // namespace fuchsia
42 } // namespace tidy
43 } // namespace clang
Loc
SourceLocation Loc
&#39;#&#39; location in the include directive
Definition: IncludeOrderCheck.cpp:36
clang::ast_matchers
Definition: ClangTidyDiagnosticConsumer.h:27
OverloadedOperatorCheck.h
clang
Definition: AndroidTidyModule.cpp:28
clang::ast_matchers::AST_MATCHER
AST_MATCHER(VarDecl, isAsm)
Definition: NoAssemblerCheck.cpp:18