[OptTable] Fix typo VALUE => VALUES (NFCI) (#121523)
[llvm-project.git] / clang / unittests / Tooling / RecursiveASTVisitorTests / CXXMethodDecl.cpp
blob1eeb3df81a3168e25d8192204a26429537c1ce65
1 //=------ unittest/Tooling/RecursiveASTVisitorTests/CXXMethodDecl.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 //===----------------------------------------------------------------------===//
9 #include "TestVisitor.h"
10 #include "clang/AST/Expr.h"
12 using namespace clang;
14 namespace {
16 class CXXMethodDeclVisitor : public ExpectedLocationVisitor {
17 public:
18 CXXMethodDeclVisitor(bool VisitImplicitCode) {
19 ShouldVisitImplicitCode = VisitImplicitCode;
22 bool VisitDeclRefExpr(DeclRefExpr *D) override {
23 Match("declref", D->getLocation());
24 return true;
27 bool VisitParmVarDecl(ParmVarDecl *P) override {
28 Match("parm", P->getLocation());
29 return true;
33 TEST(RecursiveASTVisitor, CXXMethodDeclNoDefaultBodyVisited) {
34 for (bool VisitImplCode : {false, true}) {
35 CXXMethodDeclVisitor Visitor(VisitImplCode);
36 if (VisitImplCode)
37 Visitor.ExpectMatch("declref", 8, 28);
38 else
39 Visitor.DisallowMatch("declref", 8, 28);
41 Visitor.ExpectMatch("parm", 8, 27);
42 llvm::StringRef Code = R"cpp(
43 struct B {};
44 struct A {
45 B BB;
46 A &operator=(A &&O);
49 A &A::operator=(A &&O) = default;
50 )cpp";
51 EXPECT_TRUE(Visitor.runOver(Code, CXXMethodDeclVisitor::Lang_CXX11));
55 TEST(RecursiveASTVisitor, FunctionDeclNoDefaultBodyVisited) {
56 for (bool VisitImplCode : {false, true}) {
57 CXXMethodDeclVisitor Visitor(VisitImplCode);
58 if (VisitImplCode)
59 Visitor.ExpectMatch("declref", 4, 58, /*Times=*/2);
60 else
61 Visitor.DisallowMatch("declref", 4, 58);
62 llvm::StringRef Code = R"cpp(
63 struct s {
64 int x;
65 friend auto operator==(s a, s b) -> bool = default;
67 bool k = s() == s(); // make sure clang generates the "==" definition.
68 )cpp";
69 EXPECT_TRUE(Visitor.runOver(Code, CXXMethodDeclVisitor::Lang_CXX2a));
72 } // end anonymous namespace