[PATCH] D156523: [clang][DeclPrinter] Fix AST print to suppress output of implicit (non-written) constructor initializers
Timo Stripf via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 28 04:38:34 PDT 2023
strimo378 created this revision.
strimo378 added a reviewer: aaron.ballman.
Herald added a project: All.
strimo378 requested review of this revision.
Herald added subscribers: cfe-commits, wangpc.
Herald added a project: clang.
DeclPrinter::PrintConstructorInitializers did output non-written constructor initiaizers. In particular, implicit constructor initializers of base classes were output.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D156523
Files:
clang/lib/AST/DeclPrinter.cpp
clang/test/AST/ast-print-method-decl.cpp
Index: clang/test/AST/ast-print-method-decl.cpp
===================================================================
--- clang/test/AST/ast-print-method-decl.cpp
+++ clang/test/AST/ast-print-method-decl.cpp
@@ -85,3 +85,28 @@
// CHECK-NEXT: };
};
+
+
+
+// ---- Check that implict (non-written) constructor initializers are not output
+
+struct ImplicitCtorInit1 {
+ int a;
+};
+
+// CHECK: struct ImplicitCtorInit2 : ImplicitCtorInit1 {
+struct ImplicitCtorInit2 : ImplicitCtorInit1 {
+
+ // CHECK-NEXT: ImplicitCtorInit2(int *) {
+ ImplicitCtorInit2(int *) {
+ // CHECK-NEXT: }
+ }
+
+ // CHECK-NEXT: ImplicitCtorInit2(int **) : ImplicitCtorInit1() {
+ ImplicitCtorInit2(int **) : ImplicitCtorInit1() {
+ // CHECK-NEXT: }
+ }
+
+
+ // CHECK-NEXT: };
+};
Index: clang/lib/AST/DeclPrinter.cpp
===================================================================
--- clang/lib/AST/DeclPrinter.cpp
+++ clang/lib/AST/DeclPrinter.cpp
@@ -309,6 +309,8 @@
for (const auto *BMInitializer : CDecl->inits()) {
if (BMInitializer->isInClassMemberInitializer())
continue;
+ if (!BMInitializer->isWritten())
+ continue;
if (!HasInitializerList) {
Proto += " : ";
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D156523.545102.patch
Type: text/x-patch
Size: 1201 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230728/ab87338b/attachment.bin>
More information about the cfe-commits
mailing list