Skip to content

Commit

Permalink
[clang][DeclPrinter] Fix AST print of delegating constructors
Browse files Browse the repository at this point in the history
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
  • Loading branch information
strimo378 committed Jul 26, 2023
1 parent 6fcad9c commit 2ca7416
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
2 changes: 2 additions & 0 deletions clang/lib/AST/DeclPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
48 changes: 48 additions & 0 deletions clang/test/AST/ast-print-method-decl.cpp
Original file line number Diff line number Diff line change
@@ -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: };
};

0 comments on commit 2ca7416

Please sign in to comment.