Skip to content

Commit 3e66a17

Browse files
committed
Reland [clang][DeclPrinter] Fix missing semicolon in AST print for methods that are definitions without having a body
DeclPrinter used FunctionDecl::isThisDeclarationADefinition to decide if the decl requires a semicolon at the end. However, there are several methods without body (that require a semicolon) that are definitions. Fixes #62996 Initial commit had a failing test case on targets not supporting `__attribute__((alias))`. Added `-triple i386-linux-gnu` to the specific test case. Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D156533
1 parent 649e1d1 commit 3e66a17

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

clang/lib/AST/DeclPrinter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -463,12 +463,12 @@ void DeclPrinter::VisitDeclContext(DeclContext *DC, bool Indent) {
463463
else if (isa<ObjCMethodDecl>(*D) && cast<ObjCMethodDecl>(*D)->hasBody())
464464
Terminator = nullptr;
465465
else if (auto FD = dyn_cast<FunctionDecl>(*D)) {
466-
if (FD->isThisDeclarationADefinition())
466+
if (FD->doesThisDeclarationHaveABody() && !FD->isDefaulted())
467467
Terminator = nullptr;
468468
else
469469
Terminator = ";";
470470
} else if (auto TD = dyn_cast<FunctionTemplateDecl>(*D)) {
471-
if (TD->getTemplatedDecl()->isThisDeclarationADefinition())
471+
if (TD->getTemplatedDecl()->doesThisDeclarationHaveABody())
472472
Terminator = nullptr;
473473
else
474474
Terminator = ";";

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 -ast-print %s -o - -std=c++20 | FileCheck %s
1+
// RUN: %clang_cc1 -ast-print -triple i386-linux-gnu %s -o - -std=c++20 | FileCheck %s
22

33
// CHECK: struct DelegatingCtor1 {
44
struct DelegatingCtor1 {
@@ -85,3 +85,18 @@ struct CurlyCtorInit {
8585

8686
// CHECK-NEXT: };
8787
};
88+
89+
90+
// CHECK: struct DefMethodsWithoutBody {
91+
struct DefMethodsWithoutBody {
92+
// CHECK-NEXT: DefMethodsWithoutBody() = delete;
93+
DefMethodsWithoutBody() = delete;
94+
95+
// CHECK-NEXT: DefMethodsWithoutBody() = default;
96+
~DefMethodsWithoutBody() = default;
97+
98+
// CHECK-NEXT: void m1() __attribute__((alias("X")));
99+
void m1() __attribute__((alias("X")));
100+
101+
// CHECK-NEXT: };
102+
};

0 commit comments

Comments
 (0)