[PATCH] D154186: [clang][DeclPrinter] Fix AST print of delegating constructors

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


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2ca74162258b: [clang][DeclPrinter] Fix AST print of delegating constructors (authored by strimo378).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154186/new/

https://reviews.llvm.org/D154186

Files:
  clang/lib/AST/DeclPrinter.cpp
  clang/test/AST/ast-print-method-decl.cpp


Index: clang/test/AST/ast-print-method-decl.cpp
===================================================================
--- /dev/null
+++ 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: };
+};
Index: clang/lib/AST/DeclPrinter.cpp
===================================================================
--- clang/lib/AST/DeclPrinter.cpp
+++ clang/lib/AST/DeclPrinter.cpp
@@ -321,6 +321,8 @@
     if (BMInitializer->isAnyMemberInitializer()) {
       FieldDecl *FD = BMInitializer->getAnyMember();
       Out << *FD;
+    } else if (BMInitializer->isDelegatingInitializer()) {
+      Out << CDecl->getNameAsString();
     } else {
       Out << QualType(BMInitializer->getBaseClass(), 0).getAsString(Policy);
     }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D154186.544268.patch
Type: text/x-patch
Size: 1657 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230726/5a371254/attachment.bin>


More information about the cfe-commits mailing list