[OptTable] Fix typo VALUE => VALUES (NFCI) (#121523)
[llvm-project.git] / clang-tools-extra / clang-tidy / google / OverloadedUnaryAndCheck.cpp
bloba7536607e533f55c653665c289f012385996ec36
1 //===--- OverloadedUnaryAndCheck.cpp - clang-tidy ---------------*- C++ -*-===//
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 //===----------------------------------------------------------------------===//
9 #include "OverloadedUnaryAndCheck.h"
10 #include "clang/AST/ASTContext.h"
11 #include "clang/ASTMatchers/ASTMatchFinder.h"
12 #include "clang/ASTMatchers/ASTMatchers.h"
14 using namespace clang::ast_matchers;
16 namespace clang::tidy::google::runtime {
18 void OverloadedUnaryAndCheck::registerMatchers(
19 ast_matchers::MatchFinder *Finder) {
20 // Match unary methods that overload operator&.
21 Finder->addMatcher(
22 cxxMethodDecl(parameterCountIs(0), hasOverloadedOperatorName("&"))
23 .bind("overload"),
24 this);
25 // Also match freestanding unary operator& overloads. Be careful not to match
26 // binary methods.
27 Finder->addMatcher(functionDecl(unless(cxxMethodDecl()), parameterCountIs(1),
28 hasOverloadedOperatorName("&"))
29 .bind("overload"),
30 this);
33 void OverloadedUnaryAndCheck::check(const MatchFinder::MatchResult &Result) {
34 const auto *Decl = Result.Nodes.getNodeAs<FunctionDecl>("overload");
35 diag(Decl->getBeginLoc(),
36 "do not overload unary operator&, it is dangerous.");
39 } // namespace clang::tidy::google::runtime