Skip to content

Commit 441b967

Browse files
authored
[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.
1 parent c6be456 commit 441b967

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

clang-tools-extra/clang-doc/Serialize.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,13 @@ template <typename T>
525525
static void populateInfo(Info &I, const T *D, const FullComment *C,
526526
bool &IsInAnonymousNamespace) {
527527
I.USR = getUSRForDecl(D);
528-
I.Name = D->getNameAsString();
528+
if (auto ConversionDecl = dyn_cast_or_null<CXXConversionDecl>(D);
529+
ConversionDecl && ConversionDecl->getConversionType()
530+
.getTypePtr()
531+
->isTemplateTypeParmType())
532+
I.Name = "operator " + ConversionDecl->getConversionType().getAsString();
533+
else
534+
I.Name = D->getNameAsString();
529535
populateParentNamespaces(I.Namespace, D, IsInAnonymousNamespace);
530536
if (C) {
531537
I.Description.emplace_back();

clang-tools-extra/test/clang-doc/conversion_function.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@ struct MyStruct {
1111
operator T();
1212
};
1313

14-
// Output incorrect conversion names.
15-
// CHECK-YAML: Name: 'operator type-parameter-0-0'
16-
// CHECK-YAML-NOT: Name: 'operator T'
14+
// Output correct conversion names.
15+
// CHECK-YAML: Name: 'operator T'
1716

18-
// CHECK-HTML-NOT: <h3 id='{{[0-9A-F]*}}'>operator T</h3>
19-
// CHECK-HTML-NOT: <p>public T operator T()</p>
17+
// CHECK-HTML: <h3 id='{{[0-9A-F]*}}'>operator T</h3>
18+
// CHECK-HTML: <p>public T operator T()</p>

0 commit comments

Comments
 (0)