[clang] a3da628 - [clang][DeclPrinter] Fix missing semicolon in AST print for methods that are definitions without having a body
Timo Stripf via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 28 07:52:59 PDT 2023
Author: Timo Stripf
Date: 2023-07-28T14:50:17Z
New Revision: a3da6284c23affdd9092b2641017e99d85c2d89b
URL: https://github.com/llvm/llvm-project/commit/a3da6284c23affdd9092b2641017e99d85c2d89b
DIFF: https://github.com/llvm/llvm-project/commit/a3da6284c23affdd9092b2641017e99d85c2d89b.diff
LOG: [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 https://github.com/llvm/llvm-project/issues/62996
Reviewed By: aaron.ballman
Differential Revision: https://reviews.llvm.org/D156533
Added:
Modified:
clang/lib/AST/DeclPrinter.cpp
clang/test/AST/ast-print-method-decl.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/DeclPrinter.cpp b/clang/lib/AST/DeclPrinter.cpp
index bf4d26c723d2e6..0608b48f3a880e 100644
--- a/clang/lib/AST/DeclPrinter.cpp
+++ b/clang/lib/AST/DeclPrinter.cpp
@@ -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 = ";";
diff --git a/clang/test/AST/ast-print-method-decl.cpp b/clang/test/AST/ast-print-method-decl.cpp
index 505e07dde1a868..3c3b8ceaf86389 100644
--- a/clang/test/AST/ast-print-method-decl.cpp
+++ b/clang/test/AST/ast-print-method-decl.cpp
@@ -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: };
+};
More information about the cfe-commits
mailing list