Skip to content

Commit

Permalink
[clang][DeclPrinter] Fix missing semicolon in AST print for methods t…
Browse files Browse the repository at this point in the history
…hat 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

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D156533
  • Loading branch information
strimo378 committed Jul 28, 2023
1 parent 20c92d2 commit a3da628
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions clang/lib/AST/DeclPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -463,12 +463,12 @@ void DeclPrinter::VisitDeclContext(DeclContext *DC, bool Indent) {
else if (isa<ObjCMethodDecl>(*D) && cast<ObjCMethodDecl>(*D)->hasBody())
Terminator = nullptr;
else if (auto FD = dyn_cast<FunctionDecl>(*D)) {
if (FD->isThisDeclarationADefinition())
if (FD->doesThisDeclarationHaveABody() && !FD->isDefaulted())
Terminator = nullptr;
else
Terminator = ";";
} else if (auto TD = dyn_cast<FunctionTemplateDecl>(*D)) {
if (TD->getTemplatedDecl()->isThisDeclarationADefinition())
if (TD->getTemplatedDecl()->doesThisDeclarationHaveABody())
Terminator = nullptr;
else
Terminator = ";";
Expand Down
15 changes: 15 additions & 0 deletions clang/test/AST/ast-print-method-decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,18 @@ struct CurlyCtorInit {

// CHECK-NEXT: };
};


// CHECK: struct DefMethodsWithoutBody {
struct DefMethodsWithoutBody {
// CHECK-NEXT: DefMethodsWithoutBody() = delete;
DefMethodsWithoutBody() = delete;

// CHECK-NEXT: DefMethodsWithoutBody() = default;
~DefMethodsWithoutBody() = default;

// CHECK-NEXT: void m1() __attribute__((alias("X")));
void m1() __attribute__((alias("X")));

// CHECK-NEXT: };
};

0 comments on commit a3da628

Please sign in to comment.