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

Provided by KDAB

Privacy Policy
Improve your Profiling and Debugging skills
Find out more

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