1//===- CXXOperatorCallExprTraverser.cpp -----------------------------------===//
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 "TestVisitor.h"
10
11using namespace clang;
12
13namespace {
14
15class CXXOperatorCallExprTraverser
16 : public ExpectedLocationVisitor<CXXOperatorCallExprTraverser> {
17public:
18 // Use Traverse, not Visit, to check that data recursion optimization isn't
19 // bypassing the call of this function.
20 bool TraverseCXXOperatorCallExpr(CXXOperatorCallExpr *CE) {
21 Match(Name: getOperatorSpelling(Operator: CE->getOperator()), Location: CE->getExprLoc());
22 return ExpectedLocationVisitor<CXXOperatorCallExprTraverser>::
23 TraverseCXXOperatorCallExpr(CE);
24 }
25};
26
27TEST(RecursiveASTVisitor, TraversesOverloadedOperator) {
28 CXXOperatorCallExprTraverser Visitor;
29 Visitor.ExpectMatch(Match: "()", Line: 4, Column: 9);
30 EXPECT_TRUE(Visitor.runOver(
31 "struct A {\n"
32 " int operator()();\n"
33 "} a;\n"
34 "int k = a();\n"));
35}
36
37} // end anonymous namespace
38

source code of clang/unittests/Tooling/RecursiveASTVisitorTests/CXXOperatorCallExprTraverser.cpp