Author: Timo Stripf Date: 2023-08-07T23:13:50Z New Revision: 291eb2589fdc78827af6c2c858bc5e9456e3dc20
URL: https://github.com/llvm/llvm-project/commit/291eb2589fdc78827af6c2c858bc5e9456e3dc20 DIFF: https://github.com/llvm/llvm-project/commit/291eb2589fdc78827af6c2c858bc5e9456e3dc20.diff LOG: [clang][DeclPrinter] Fix AST print to suppress output of implicit (non-written) constructor initializers DeclPrinter::PrintConstructorInitializers did output non-written constructor initiaizers. In particular, implicit constructor initializers of base classes were output. Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D156523 Added: Modified: clang/lib/AST/DeclPrinter.cpp clang/test/AST/ast-print-method-decl.cpp Removed: ################################################################################ diff --git a/clang/lib/AST/DeclPrinter.cpp b/clang/lib/AST/DeclPrinter.cpp index 0608b48f3a880e..034fc874bd882b 100644 --- a/clang/lib/AST/DeclPrinter.cpp +++ b/clang/lib/AST/DeclPrinter.cpp @@ -309,6 +309,8 @@ void DeclPrinter::PrintConstructorInitializers(CXXConstructorDecl *CDecl, for (const auto *BMInitializer : CDecl->inits()) { if (BMInitializer->isInClassMemberInitializer()) continue; + if (!BMInitializer->isWritten()) + continue; if (!HasInitializerList) { Proto += " : "; diff --git a/clang/test/AST/ast-print-method-decl.cpp b/clang/test/AST/ast-print-method-decl.cpp index 928687b4b35894..37ddefcb611e18 100644 --- a/clang/test/AST/ast-print-method-decl.cpp +++ b/clang/test/AST/ast-print-method-decl.cpp @@ -100,3 +100,26 @@ struct DefMethodsWithoutBody { // 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: }; +}; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits