[clang] [ExtractAPI] Include tilde in destructor name (PR #146001)
Prajwal Nadig via cfe-commits
cfe-commits at lists.llvm.org
Thu Jun 26 18:15:16 PDT 2025
https://github.com/snprajwal created https://github.com/llvm/llvm-project/pull/146001
The subheading for a destructor contained only the identifier. The tilde must also be included as it is necessary to differentiate the destructor from any constructors present.
rdar://129587608
>From a1d27fd6458c6f05a583a79449c13bad56e7cea0 Mon Sep 17 00:00:00 2001
From: Prajwal Nadig <pnadig at apple.com>
Date: Fri, 27 Jun 2025 01:52:58 +0100
Subject: [PATCH] [ExtractAPI] Include tilde in destructor name
The subheading for a destructor contained only the identifier. The tilde
must also be included as it is necessary to differentiate the destructor
from any constructors present.
rdar://129587608
---
clang/lib/ExtractAPI/DeclarationFragments.cpp | 11 ++++++++---
clang/test/ExtractAPI/constructor_destructor.cpp | 2 +-
2 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/clang/lib/ExtractAPI/DeclarationFragments.cpp b/clang/lib/ExtractAPI/DeclarationFragments.cpp
index 348e7588690a2..62b69436c0f97 100644
--- a/clang/lib/ExtractAPI/DeclarationFragments.cpp
+++ b/clang/lib/ExtractAPI/DeclarationFragments.cpp
@@ -1610,10 +1610,13 @@ DeclarationFragmentsBuilder::getFunctionSignature(const ObjCMethodDecl *);
DeclarationFragments
DeclarationFragmentsBuilder::getSubHeading(const NamedDecl *Decl) {
DeclarationFragments Fragments;
- if (isa<CXXConstructorDecl>(Decl) || isa<CXXDestructorDecl>(Decl))
+ if (isa<CXXConstructorDecl>(Decl)) {
Fragments.append(cast<CXXRecordDecl>(Decl->getDeclContext())->getName(),
DeclarationFragments::FragmentKind::Identifier);
- else if (isa<CXXConversionDecl>(Decl)) {
+ } else if (isa<CXXDestructorDecl>(Decl)) {
+ Fragments.append(cast<CXXDestructorDecl>(Decl)->getNameAsString(),
+ DeclarationFragments::FragmentKind::Identifier);
+ } else if (isa<CXXConversionDecl>(Decl)) {
Fragments.append(
cast<CXXConversionDecl>(Decl)->getConversionType().getAsString(),
DeclarationFragments::FragmentKind::Identifier);
@@ -1627,9 +1630,11 @@ DeclarationFragmentsBuilder::getSubHeading(const NamedDecl *Decl) {
} else if (Decl->getIdentifier()) {
Fragments.append(Decl->getName(),
DeclarationFragments::FragmentKind::Identifier);
- } else
+ } else {
Fragments.append(Decl->getDeclName().getAsString(),
DeclarationFragments::FragmentKind::Identifier);
+ }
+
return Fragments;
}
diff --git a/clang/test/ExtractAPI/constructor_destructor.cpp b/clang/test/ExtractAPI/constructor_destructor.cpp
index 27112c95ac45c..2f2150a6d0da0 100644
--- a/clang/test/ExtractAPI/constructor_destructor.cpp
+++ b/clang/test/ExtractAPI/constructor_destructor.cpp
@@ -213,7 +213,7 @@ class Foo {
"subHeading": [
{
"kind": "identifier",
- "spelling": "Foo"
+ "spelling": "~Foo"
}
],
"title": "~Foo"
More information about the cfe-commits
mailing list