[PATCH] D65735: [AST] Fix RecursiveASTVisitor visiting implicit constructor initializers.
Johan Vikström via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 5 05:20:24 PDT 2019
This revision was automatically updated to reflect the committed changes.
jvikstrom marked an inline comment as done.
Closed by commit rL367839: [AST] Fix RecursiveASTVisitor visiting implicit constructor initializers. (authored by jvikstrom, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Changed prior to commit:
https://reviews.llvm.org/D65735?vs=213323&id=213329#toc
Repository:
rL LLVM
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D65735/new/
https://reviews.llvm.org/D65735
Files:
cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
cfe/trunk/unittests/Tooling/CMakeLists.txt
cfe/trunk/unittests/Tooling/RecursiveASTVisitorTests/ImplicitCtorInitializer.cpp
Index: cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
===================================================================
--- cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
+++ cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
@@ -2023,7 +2023,8 @@
if (CXXConstructorDecl *Ctor = dyn_cast<CXXConstructorDecl>(D)) {
// Constructor initializers.
for (auto *I : Ctor->inits()) {
- TRY_TO(TraverseConstructorInitializer(I));
+ if (I->isWritten() || getDerived().shouldVisitImplicitCode())
+ TRY_TO(TraverseConstructorInitializer(I));
}
}
Index: cfe/trunk/unittests/Tooling/RecursiveASTVisitorTests/ImplicitCtorInitializer.cpp
===================================================================
--- cfe/trunk/unittests/Tooling/RecursiveASTVisitorTests/ImplicitCtorInitializer.cpp
+++ cfe/trunk/unittests/Tooling/RecursiveASTVisitorTests/ImplicitCtorInitializer.cpp
@@ -0,0 +1,57 @@
+//=- unittest/Tooling/RecursiveASTVisitorTests/ImplicitCtorInitializer.cpp -=//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "TestVisitor.h"
+
+using namespace clang;
+
+namespace {
+
+class CXXCtorInitializerVisitor
+ : public ExpectedLocationVisitor<CXXCtorInitializerVisitor> {
+public:
+ CXXCtorInitializerVisitor(bool VisitImplicitCode)
+ : VisitImplicitCode(VisitImplicitCode) {}
+
+ bool shouldVisitImplicitCode() const { return VisitImplicitCode; }
+
+ bool TraverseConstructorInitializer(CXXCtorInitializer *Init) {
+ if (!Init->isWritten())
+ VisitedImplicitInitializer = true;
+ Match("initializer", Init->getSourceLocation());
+ return ExpectedLocationVisitor<
+ CXXCtorInitializerVisitor>::TraverseConstructorInitializer(Init);
+ }
+
+ bool VisitedImplicitInitializer = false;
+
+private:
+ bool VisitImplicitCode;
+};
+
+// Check to ensure that CXXCtorInitializer is not visited when implicit code
+// should not be visited and that it is visited when implicit code should be
+// visited.
+TEST(RecursiveASTVisitor, CXXCtorInitializerVisitNoImplicit) {
+ for (bool VisitImplCode : {true, false}) {
+ CXXCtorInitializerVisitor Visitor(VisitImplCode);
+ Visitor.ExpectMatch("initializer", 7, 17);
+ EXPECT_TRUE(Visitor.runOver(R"cpp(
+ class A {};
+ class B : public A {
+ B() {};
+ };
+ class C : public A {
+ C() : A() {}
+ };
+ )cpp",
+ CXXCtorInitializerVisitor::Lang_CXX));
+ EXPECT_EQ(Visitor.VisitedImplicitInitializer, VisitImplCode);
+ }
+}
+} // end anonymous namespace
Index: cfe/trunk/unittests/Tooling/CMakeLists.txt
===================================================================
--- cfe/trunk/unittests/Tooling/CMakeLists.txt
+++ cfe/trunk/unittests/Tooling/CMakeLists.txt
@@ -31,6 +31,7 @@
RecursiveASTVisitorTests/CXXOperatorCallExprTraverser.cpp
RecursiveASTVisitorTests/DeclRefExpr.cpp
RecursiveASTVisitorTests/ImplicitCtor.cpp
+ RecursiveASTVisitorTests/ImplicitCtorInitializer.cpp
RecursiveASTVisitorTests/InitListExprPostOrder.cpp
RecursiveASTVisitorTests/InitListExprPostOrderNoQueue.cpp
RecursiveASTVisitorTests/InitListExprPreOrder.cpp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D65735.213329.patch
Type: text/x-patch
Size: 3419 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190805/c5bb7f8e/attachment.bin>
More information about the cfe-commits
mailing list