[clang-tools-extra] [clang-doc] fix names of conversions for template parameters (PR #140856)
Erick Velez via cfe-commits
cfe-commits at lists.llvm.org
Thu May 22 14:16:55 PDT 2025
https://github.com/evelez7 updated https://github.com/llvm/llvm-project/pull/140856
>From e25581d28ecda89fe4e550da71e668b6ae749804 Mon Sep 17 00:00:00 2001
From: Erick Velez <erickvelez7 at gmail.com>
Date: Tue, 20 May 2025 23:26:02 -0700
Subject: [PATCH 1/2] [clang-doc] fix conversion names of dependent types
Fixes #59812
The names of conversion functions of template type parameters were
being emitted as "type-parameter-N-M". Now we check if the conversion
type is a TemplateTypeParmType and reconstruct the source name.
---
clang-tools-extra/clang-doc/Serialize.cpp | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/clang-tools-extra/clang-doc/Serialize.cpp b/clang-tools-extra/clang-doc/Serialize.cpp
index 18db427b5239e..585a46112d43d 100644
--- a/clang-tools-extra/clang-doc/Serialize.cpp
+++ b/clang-tools-extra/clang-doc/Serialize.cpp
@@ -525,7 +525,13 @@ template <typename T>
static void populateInfo(Info &I, const T *D, const FullComment *C,
bool &IsInAnonymousNamespace) {
I.USR = getUSRForDecl(D);
- I.Name = D->getNameAsString();
+ auto ConversionDecl = dyn_cast_or_null<CXXConversionDecl>(D);
+ if (ConversionDecl && ConversionDecl->getConversionType()
+ .getTypePtr()
+ ->isTemplateTypeParmType())
+ I.Name = "operator " + ConversionDecl->getConversionType().getAsString();
+ else
+ I.Name = D->getNameAsString();
populateParentNamespaces(I.Namespace, D, IsInAnonymousNamespace);
if (C) {
I.Description.emplace_back();
>From a4d5ad45cad45f21505fdd8e88e2706dc3343e88 Mon Sep 17 00:00:00 2001
From: Erick Velez <erickvelez7 at gmail.com>
Date: Thu, 22 May 2025 14:14:26 -0700
Subject: [PATCH 2/2] address review feedback
---
clang-tools-extra/clang-doc/Serialize.cpp | 4 ++--
.../test/clang-doc/conversion_function.cpp | 17 +++++++++++++++++
2 files changed, 19 insertions(+), 2 deletions(-)
create mode 100644 clang-tools-extra/test/clang-doc/conversion_function.cpp
diff --git a/clang-tools-extra/clang-doc/Serialize.cpp b/clang-tools-extra/clang-doc/Serialize.cpp
index 585a46112d43d..fe4ef9c50cc12 100644
--- a/clang-tools-extra/clang-doc/Serialize.cpp
+++ b/clang-tools-extra/clang-doc/Serialize.cpp
@@ -525,8 +525,8 @@ template <typename T>
static void populateInfo(Info &I, const T *D, const FullComment *C,
bool &IsInAnonymousNamespace) {
I.USR = getUSRForDecl(D);
- auto ConversionDecl = dyn_cast_or_null<CXXConversionDecl>(D);
- if (ConversionDecl && ConversionDecl->getConversionType()
+ if (auto ConversionDecl = dyn_cast_or_null<CXXConversionDecl>(D);
+ ConversionDecl && ConversionDecl->getConversionType()
.getTypePtr()
->isTemplateTypeParmType())
I.Name = "operator " + ConversionDecl->getConversionType().getAsString();
diff --git a/clang-tools-extra/test/clang-doc/conversion_function.cpp b/clang-tools-extra/test/clang-doc/conversion_function.cpp
new file mode 100644
index 0000000000000..fee86b356011e
--- /dev/null
+++ b/clang-tools-extra/test/clang-doc/conversion_function.cpp
@@ -0,0 +1,17 @@
+// RUN: rm -rf %t && mkdir -p %t
+
+// RUN: clang-doc --output=%t --executor=standalone %s
+// RUN: find %t/ -regex ".*/[0-9A-F]*.yaml" -exec cat {} ";" | FileCheck %s --check-prefix=CHECK-YAML
+
+// RUN: clang-doc --format=html --output=%t --executor=standalone %s
+// FileCheck %s --check-prefix=CHECK-HTML
+
+template <typename T>
+struct MyStruct {
+ operator T();
+};
+
+// CHECK-YAML: Name: 'operator T'
+
+// CHECK-HTML: <h3 id='{{[0-9A-F]*}}'>operator T</h3>
+// CHECK-HTML: <p>public T operator T</p>
More information about the cfe-commits
mailing list