clang-tools  10.0.0git
OverloadedOperatorCheck.cpp
Go to the documentation of this file.
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 
10 
11 using namespace clang::ast_matchers;
12 
13 namespace clang {
14 namespace tidy {
15 namespace fuchsia {
16 
17 namespace {
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  if (CXXMethodNode->getParent()->isLambda())
24  return false;
25  }
26  return Node.isOverloadedOperator();
27 }
28 } // namespace
29 
30 void OverloadedOperatorCheck::registerMatchers(MatchFinder *Finder) {
31  Finder->addMatcher(functionDecl(isFuchsiaOverloadedOperator()).bind("decl"),
32  this);
33 }
34 
35 void OverloadedOperatorCheck::check(const MatchFinder::MatchResult &Result) {
36  const auto *D = Result.Nodes.getNodeAs<FunctionDecl>("decl");
37  assert(D && "No FunctionDecl captured!");
38 
39  SourceLocation Loc = D->getBeginLoc();
40  if (Loc.isValid())
41  diag(Loc, "overloading %0 is disallowed") << D;
42 }
43 
44 } // namespace fuchsia
45 } // namespace tidy
46 } // namespace clang
SourceLocation Loc
&#39;#&#39; location in the include directive
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//