[clang-tools-extra] 441b967 - [clang-doc] fix names of conversions for template parameters (#140856)

via cfe-commits cfe-commits at lists.llvm.org
Fri May 23 12:35:36 PDT 2025


Author: Erick Velez
Date: 2025-05-23T19:35:32Z
New Revision: 441b967ad919de182f54929de701b945a69449c9

URL: https://github.com/llvm/llvm-project/commit/441b967ad919de182f54929de701b945a69449c9
DIFF: https://github.com/llvm/llvm-project/commit/441b967ad919de182f54929de701b945a69449c9.diff

LOG: [clang-doc] fix names of conversions for template parameters (#140856)

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.

Added: 
    

Modified: 
    clang-tools-extra/clang-doc/Serialize.cpp
    clang-tools-extra/test/clang-doc/conversion_function.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clang-doc/Serialize.cpp b/clang-tools-extra/clang-doc/Serialize.cpp
index 18db427b5239e..fe4ef9c50cc12 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();
+  if (auto ConversionDecl = dyn_cast_or_null<CXXConversionDecl>(D);
+      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();

diff  --git a/clang-tools-extra/test/clang-doc/conversion_function.cpp b/clang-tools-extra/test/clang-doc/conversion_function.cpp
index ebde35e38278d..bf97d85661346 100644
--- a/clang-tools-extra/test/clang-doc/conversion_function.cpp
+++ b/clang-tools-extra/test/clang-doc/conversion_function.cpp
@@ -11,9 +11,8 @@ struct MyStruct {
   operator T();
 };
 
-// Output incorrect conversion names.
-// CHECK-YAML:         Name:            'operator type-parameter-0-0'
-// CHECK-YAML-NOT:     Name:            'operator T'
+// Output correct conversion names.
+// CHECK-YAML:         Name:            'operator T'
 
-// CHECK-HTML-NOT: <h3 id='{{[0-9A-F]*}}'>operator T</h3>
-// CHECK-HTML-NOT: <p>public T operator T()</p>
+// 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