Skip to content

Commit 966e652

Browse files
committed
fix: empty argument list stripped from template rendering
`T<>`, a class template specialization with an empty argument list, was incorrectly rendered as `T`. Closes issue #1184.
1 parent 9c7a140 commit 966e652

7 files changed

Lines changed: 223 additions & 4 deletions

File tree

share/mrdocs/addons/generator/common/partials/type/name-infos.hbs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,11 @@
2727
{{! No link, just the name. ~}}
2828
{{name~}}
2929
{{/if~}}
30-
{{#if args~}}
31-
{{! Render the template arguments of the symbol. ~}}
30+
{{#if (eq kind "specialization")~}}
31+
{{! Render the template arguments of the symbol. The
32+
check is on `kind` rather than `args`, since an empty
33+
argument list is still meaningful: `T<>` must render
34+
as `T<>`, not `T`. ~}}
3235
{{>template/args args=args link-components-impl=link-components-impl~}}
3336
{{/if~}}
3437
{{/if~}}

test-files/golden-tests/templates/at_dtst.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Declared in `&lt;at&lowbar;dtst&period;cpp&gt;`
2222
[source,cpp,subs="verbatim,replacements,macros,-callouts"]
2323
----
2424
template&lt;class T&gt;
25-
using A = T::XX;
25+
using A = T::XX&lt;&gt;;
2626
----
2727

2828

test-files/golden-tests/templates/at_dtst.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ <h3>
3737
<div>
3838
Declared in <code>&lt;at_dtst.cpp&gt;</code></div>
3939
<pre><code class="source-code cpp">template&lt;class T&gt;
40-
using A = T::XX;</code></pre>
40+
using A = T::XX&lt;&gt;;</code></pre>
4141
</div>
4242
</div>
4343

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
= Reference
2+
:mrdocs:
3+
4+
[#index]
5+
== Global namespace
6+
7+
=== Types
8+
9+
[cols=1]
10+
|===
11+
| Name
12+
| link:#Task[`Task`]
13+
|===
14+
15+
=== Functions
16+
17+
[cols=1]
18+
|===
19+
| Name
20+
| link:#handshake[`handshake`]
21+
|===
22+
23+
[#Task]
24+
== Task
25+
26+
=== Synopsis
27+
28+
Declared in `&lt;empty&lowbar;template&lowbar;args&period;cpp&gt;`
29+
30+
[source,cpp,subs="verbatim,replacements,macros,-callouts"]
31+
----
32+
template&lt;typename T = int&gt;
33+
struct Task;
34+
----
35+
36+
[#handshake]
37+
== handshake
38+
39+
=== Synopsis
40+
41+
Declared in `&lt;empty&lowbar;template&lowbar;args&period;cpp&gt;`
42+
43+
[source,cpp,subs="verbatim,replacements,macros,-callouts"]
44+
----
45+
link:#Task[Task&lt;&gt;]
46+
handshake();
47+
----
48+
49+
50+
[.small]#Created with https://www.mrdocs.com[MrDocs]#
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// A class template with a default template argument, used as a
2+
// function return type via the empty-argument-list specialization
3+
// `Task<>`. The rendered output should preserve the angle brackets
4+
// (`Task<>`), not collapse to `Task`. See issue #1184.
5+
6+
template <typename T = int>
7+
struct Task {};
8+
9+
Task<> handshake();
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<html lang="en">
2+
<head>
3+
<title>Reference</title>
4+
<meta charset="utf-8">
5+
</head>
6+
<body>
7+
<div>
8+
<h1>Reference</h1>
9+
<div>
10+
<div>
11+
<h2 id="index">
12+
Global Namespace</h2>
13+
</div>
14+
<h2>
15+
Types</h2>
16+
<table style="table-layout: fixed; width: 100%;">
17+
<thead>
18+
<tr>
19+
<th>Name</th>
20+
</tr>
21+
</thead>
22+
<tbody>
23+
<tr>
24+
<td><a href="#Task"><code>Task</code></a> </td></tr>
25+
</tbody>
26+
</table>
27+
28+
<h2>
29+
Functions</h2>
30+
<table style="table-layout: fixed; width: 100%;">
31+
<thead>
32+
<tr>
33+
<th>Name</th>
34+
</tr>
35+
</thead>
36+
<tbody>
37+
<tr>
38+
<td><a href="#handshake"><code>handshake</code></a> </td></tr>
39+
</tbody>
40+
</table>
41+
42+
</div>
43+
<div>
44+
<div>
45+
<h2 id="Task">
46+
Task</h2>
47+
</div>
48+
<div>
49+
<h3>
50+
Synopsis</h3>
51+
<div>
52+
Declared in <code>&lt;empty_template_args.cpp&gt;</code></div>
53+
<pre><code class="source-code cpp">template&lt;typename T = int&gt;
54+
struct Task;</code></pre>
55+
</div>
56+
57+
58+
</div>
59+
<div>
60+
<div>
61+
<h2 id="handshake">
62+
handshake</h2>
63+
</div>
64+
<div>
65+
<h3>
66+
Synopsis</h3>
67+
<div>
68+
Declared in <code>&lt;empty_template_args.cpp&gt;</code></div>
69+
<pre><code class="source-code cpp"><a href="#Task">Task&lt;&gt;</a>
70+
handshake();</code></pre>
71+
</div>
72+
</div>
73+
74+
</div>
75+
<footer class="mrdocs-footer">
76+
<span>Created with <a href="https://www.mrdocs.com">MrDocs</a></span>
77+
</footer>
78+
</body>
79+
</html>
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<mrdocs xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="https://github.com/cppalliance/mrdocs/raw/develop/mrdocs.rnc">
4+
<namespace>
5+
<source>
6+
</source>
7+
<kind>namespace</kind>
8+
<id>//////////////////////////8=</id>
9+
<extraction>regular</extraction>
10+
<namespace-tranche>
11+
<records>OaOnBHKCiwPzSl9scjYZHnbbONQ=</records>
12+
<functions>l1bUVBI7Kj1W/LknqpflEcOAnWQ=</functions>
13+
</namespace-tranche>
14+
</namespace>
15+
<record>
16+
<name>Task</name>
17+
<source>
18+
<location>
19+
<short-path>empty_template_args.cpp</short-path>
20+
<source-path>empty_template_args.cpp</source-path>
21+
<line-number>6</line-number>
22+
<column-number>1</column-number>
23+
</location>
24+
</source>
25+
<kind>record</kind>
26+
<id>OaOnBHKCiwPzSl9scjYZHnbbONQ=</id>
27+
<extraction>regular</extraction>
28+
<parent>//////////////////////////8=</parent>
29+
<key-kind>struct</key-kind>
30+
<template>
31+
<type-tparam>
32+
<kind>type</kind>
33+
<name>T</name>
34+
<type-targ>
35+
<kind>type</kind>
36+
<named>
37+
<name>
38+
<kind>identifier</kind>
39+
<identifier>int</identifier>
40+
</name>
41+
</named>
42+
</type-targ>
43+
<key-kind>typename</key-kind>
44+
</type-tparam>
45+
</template>
46+
<record-interface>
47+
<record-tranche>
48+
</record-tranche>
49+
<record-tranche>
50+
</record-tranche>
51+
<record-tranche>
52+
</record-tranche>
53+
</record-interface>
54+
</record>
55+
<function>
56+
<name>handshake</name>
57+
<source>
58+
<location>
59+
<short-path>empty_template_args.cpp</short-path>
60+
<source-path>empty_template_args.cpp</source-path>
61+
<line-number>9</line-number>
62+
<column-number>1</column-number>
63+
</location>
64+
</source>
65+
<kind>function</kind>
66+
<id>l1bUVBI7Kj1W/LknqpflEcOAnWQ=</id>
67+
<extraction>regular</extraction>
68+
<parent>//////////////////////////8=</parent>
69+
<named>
70+
<name>
71+
<kind>specialization</kind>
72+
<id>OaOnBHKCiwPzSl9scjYZHnbbONQ=</id>
73+
<identifier>Task</identifier>
74+
</name>
75+
</named>
76+
<func-class>normal</func-class>
77+
</function>
78+
</mrdocs>

0 commit comments

Comments
 (0)