[clang] 2ca7416 - [clang][DeclPrinter] Fix AST print of delegating constructors

Timo Stripf via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 26 02:30:03 PDT 2023


Author: Timo Stripf
Date: 2023-07-26T09:26:53Z
New Revision: 2ca74162258b6e808e84d6700a5613c0cbf6efe9

URL: https://github.com/llvm/llvm-project/commit/2ca74162258b6e808e84d6700a5613c0cbf6efe9
DIFF: https://github.com/llvm/llvm-project/commit/2ca74162258b6e808e84d6700a5613c0cbf6efe9.diff

LOG: [clang][DeclPrinter] Fix AST print of delegating constructors

DeclPrinter::PrintConstructorInitializers did not consider delegating initializers. As result, the output contained an "NULL TYPE" for delegating constructors.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D154186

Added: 
    clang/test/AST/ast-print-method-decl.cpp

Modified: 
    clang/lib/AST/DeclPrinter.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/DeclPrinter.cpp b/clang/lib/AST/DeclPrinter.cpp
index a6a9911c8992aa..de33d79eeb484e 100644
--- a/clang/lib/AST/DeclPrinter.cpp
+++ b/clang/lib/AST/DeclPrinter.cpp
@@ -321,6 +321,8 @@ void DeclPrinter::PrintConstructorInitializers(CXXConstructorDecl *CDecl,
     if (BMInitializer->isAnyMemberInitializer()) {
       FieldDecl *FD = BMInitializer->getAnyMember();
       Out << *FD;
+    } else if (BMInitializer->isDelegatingInitializer()) {
+      Out << CDecl->getNameAsString();
     } else {
       Out << QualType(BMInitializer->getBaseClass(), 0).getAsString(Policy);
     }

diff  --git a/clang/test/AST/ast-print-method-decl.cpp b/clang/test/AST/ast-print-method-decl.cpp
new file mode 100644
index 00000000000000..4a3f5440fe158b
--- /dev/null
+++ b/clang/test/AST/ast-print-method-decl.cpp
@@ -0,0 +1,48 @@
+// RUN: %clang_cc1 -ast-print %s -o - -std=c++20 | FileCheck %s
+
+// CHECK: struct A {
+struct A {
+  // CHECK-NEXT: A();
+  A();
+
+  // CHECK-NEXT: A(int) : A() {
+  A(int) : A() {
+    // CHECK-NEXT: }
+  }
+
+  // CHECK-NEXT: };
+};
+
+
+// CHECK: struct B {
+struct B {
+  // CHECK-NEXT: template <typename Ty> B(Ty);
+  template <typename Ty> B(Ty);
+
+  // FIXME: Implicitly specialized method should not be output
+  // CHECK-NEXT: template<> B<float>(float);
+
+  // CHECK-NEXT: B(int X) : B((float)X) {
+  B(int X) : B((float)X) {
+  // CHECK-NEXT: }
+  }
+
+  // CHECK-NEXT: };
+};
+
+// CHECK: struct C {
+struct C {
+  // FIXME: template <> should not be output
+  // CHECK: template <> C(auto);
+  C(auto);
+
+  // FIXME: Implicitly specialized method should not be output
+  // CHECK: template<> C<const char *>(const char *);
+
+  // CHECK: C(int) : C("") {
+  C(int) : C("") {
+  // CHECK-NEXT: }
+  }
+
+  // CHECK-NEXT: };
+};


        


More information about the cfe-commits mailing list