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 11 using namespace clang; 12 13 namespace { 14 15 class CXXOperatorCallExprTraverser : public ExpectedLocationVisitor { 16 public: 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(CE->getOperator()), CE->getExprLoc()); 21 return ExpectedLocationVisitor::TraverseCXXOperatorCallExpr(CE); 22 } 23 }; 24 25 TEST(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