36 lines · cpp
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-exception6//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't18 // bypassing the call of this function.19 bool TraverseCXXOperatorCallExpr(CXXOperatorCallExpr *CE) override {20 Match(getOperatorSpelling(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 namespace36