Skip to content

Commit e2c8aac

Browse files
authored
fix: don't mark unnamed classes as implementation defined
These classes can appear as user written code and needs to be documented, as show in the new test case. In general, for implementation defined declarations, we can detect them as the clang AST exposes them as 'implicit', but this is possible for any declaration, and can be handled more generally. The new included exposes a different bug, where we don't attach the documentation provided for each member in a declarator, which clang does expose in the AST, but we seem to be ignoring it.
1 parent ffc2762 commit e2c8aac

File tree

5 files changed

+333
-13
lines changed

5 files changed

+333
-13
lines changed

src/lib/AST/ASTVisitor.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -644,15 +644,6 @@ populate(
644644
RecordInfo& I,
645645
CXXRecordDecl const* D)
646646
{
647-
// Unnamed structs and classes are implementation-defined
648-
// or dependencies at best. There are never pages for them.
649-
if (D->getIdentifier() == nullptr)
650-
{
651-
I.Extraction = mostSpecific(
652-
ExtractionMode::ImplementationDefined,
653-
I.Extraction);
654-
}
655-
656647
if (D->getTypedefNameForAnonDecl())
657648
{
658649
I.IsTypeDef = true;

test-files/golden-tests/symbols/record/unnamed.adoc

Lines changed: 121 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,102 @@
44
[#index]
55
== Global namespace
66

7+
=== Types
8+
9+
[cols=2]
10+
|===
11+
| Name
12+
| Description
13+
| link:#_01record-01[`Unnamed struct`]
14+
|
15+
| link:#_01record-0f[`Unnamed struct`]
16+
| A test unnamed class.
17+
|===
18+
719
=== Variables
820

9-
[cols=1]
21+
[cols=2]
1022
|===
1123
| Name
24+
| Description
1225
| link:#F[`F`]
26+
|
27+
| link:#x[`x`]
28+
| A test variable named 'x'
29+
| link:#y[`y`]
30+
| A test variable named 'y'
31+
|===
32+
33+
[#_01record-01]
34+
== Unnamed struct
35+
36+
=== Synopsis
37+
38+
Declared in `<unnamed.cpp>`
39+
40+
[source,cpp,subs="verbatim,replacements,macros,-callouts"]
41+
----
42+
struct Unnamed struct;
43+
----
44+
45+
=== Member Functions
46+
47+
[cols=1]
1348
|===
49+
| Name
50+
| link:#_01record-01-operator_call[`operator()`]
51+
|===
52+
53+
[#_01record-01-operator_call]
54+
== operator()
55+
56+
=== Synopsis
57+
58+
Declared in `<unnamed.cpp>`
59+
60+
[source,cpp,subs="verbatim,replacements,macros,-callouts"]
61+
----
62+
void
63+
operator()() const;
64+
----
65+
66+
[#_01record-0f]
67+
== Unnamed struct
68+
69+
A test unnamed class.
70+
71+
=== Synopsis
72+
73+
Declared in `<unnamed.cpp>`
74+
75+
[source,cpp,subs="verbatim,replacements,macros,-callouts"]
76+
----
77+
struct Unnamed struct;
78+
----
79+
80+
=== Data Members
81+
82+
[cols=2]
83+
|===
84+
| Name
85+
| Description
86+
| link:#_01record-0f-a[`a`]
87+
| A test field.
88+
|===
89+
90+
[#_01record-0f-a]
91+
== a
92+
93+
A test field.
94+
95+
=== Synopsis
96+
97+
Declared in `<unnamed.cpp>`
98+
99+
[source,cpp,subs="verbatim,replacements,macros,-callouts"]
100+
----
101+
int a;
102+
----
14103

15104
[#F]
16105
== F
@@ -21,7 +110,37 @@ Declared in `<unnamed.cpp>`
21110

22111
[source,cpp,subs="verbatim,replacements,macros,-callouts"]
23112
----
24-
constexpr /* implementation-defined */ F = {};
113+
constexpr link:#_01record-01[] F = {};
114+
----
115+
116+
[#x]
117+
== x
118+
119+
A test variable named 'x'
120+
121+
=== Synopsis
122+
123+
Declared in `<unnamed.cpp>`
124+
125+
[source,cpp,subs="verbatim,replacements,macros,-callouts"]
126+
----
127+
extern
128+
link:#_01record-0f[] x;
129+
----
130+
131+
[#y]
132+
== y
133+
134+
A test variable named 'y'
135+
136+
=== Synopsis
137+
138+
Declared in `<unnamed.cpp>`
139+
140+
[source,cpp,subs="verbatim,replacements,macros,-callouts"]
141+
----
142+
extern
143+
link:#_01record-0f[] y;
25144
----
26145

27146

test-files/golden-tests/symbols/record/unnamed.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,13 @@ constexpr struct
22
{
33
void operator()() const;
44
} const F{};
5+
6+
/// A test unnamed class.
7+
extern struct {
8+
/// A test field.
9+
int a;
10+
}
11+
/// A test variable named 'x'
12+
x,
13+
/// A test variable named 'y'
14+
y;

test-files/golden-tests/symbols/record/unnamed.html

Lines changed: 160 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,137 @@ <h1>Reference</h1>
99
<div>
1010
<h2 id="index"><a href="#index"></a></h2>
1111
</div>
12+
<h2>Types</h2>
13+
<table style="table-layout: fixed; width: 100%;">
14+
<thead>
15+
<tr>
16+
<th>Name</th>
17+
<th>Description</th>
18+
</tr>
19+
</thead>
20+
<tbody>
21+
<tr>
22+
<td><a href="#_01record-01"><code>Unnamed struct</code></a> </td><td><span></span></td></tr><tr>
23+
<td><a href="#_01record-0f"><code>Unnamed struct</code></a> </td><td><span>A test unnamed class.</span></td></tr>
24+
</tbody>
25+
</table>
26+
1227
<h2>Variables</h2>
1328
<table style="table-layout: fixed; width: 100%;">
1429
<thead>
1530
<tr>
1631
<th>Name</th>
32+
<th>Description</th>
33+
</tr>
34+
</thead>
35+
<tbody>
36+
<tr>
37+
<td><a href="#F"><code>F</code></a> </td><td><span></span></td></tr><tr>
38+
<td><a href="#x"><code>x</code></a> </td><td><span>A test variable named &#x27;x&#x27;</span></td></tr><tr>
39+
<td><a href="#y"><code>y</code></a> </td><td><span>A test variable named &#x27;y&#x27;</span></td></tr>
40+
</tbody>
41+
</table>
42+
43+
</div>
44+
<div>
45+
<div>
46+
<h2 id="_01record-01"><a href="#_01record-01"></a></h2>
47+
</div>
48+
<div>
49+
<h3>Synopsis</h3>
50+
<div>
51+
Declared in <code>&lt;unnamed.cpp&gt;</code></div>
52+
<pre>
53+
<code class="source-code cpp">struct Unnamed struct;
54+
55+
</code>
56+
</pre>
57+
</div>
58+
<h2>Member Functions</h2>
59+
<table style="table-layout: fixed; width: 100%;">
60+
<thead>
61+
<tr>
62+
<th>Name</th>
1763
</tr>
1864
</thead>
1965
<tbody>
2066
<tr>
21-
<td><a href="#F"><code>F</code></a> </td></tr>
67+
<td><a href="#_01record-01-operator_call"><code>operator()</code></a> </td></tr>
2268
</tbody>
2369
</table>
2470

71+
72+
73+
</div>
74+
<div>
75+
<div>
76+
<h2 id="_01record-01-operator_call"><a href="#_01record-01-operator_call">::operator()</a></h2>
77+
</div>
78+
<div>
79+
<h3>Synopsis</h3>
80+
<div>
81+
Declared in <code>&lt;unnamed.cpp&gt;</code></div>
82+
<pre>
83+
<code class="source-code cpp">void
84+
operator()() const;
85+
86+
</code>
87+
</pre>
88+
</div>
89+
</div>
90+
<div>
91+
<div>
92+
<h2 id="_01record-0f"><a href="#_01record-0f"></a></h2>
93+
<div>
94+
<span>A test unnamed class.</span>
95+
96+
</div>
97+
</div>
98+
<div>
99+
<h3>Synopsis</h3>
100+
<div>
101+
Declared in <code>&lt;unnamed.cpp&gt;</code></div>
102+
<pre>
103+
<code class="source-code cpp">struct Unnamed struct;
104+
105+
</code>
106+
</pre>
107+
</div>
108+
<h2>Data Members</h2>
109+
<table style="table-layout: fixed; width: 100%;">
110+
<thead>
111+
<tr>
112+
<th>Name</th>
113+
<th>Description</th>
114+
</tr>
115+
</thead>
116+
<tbody>
117+
<tr>
118+
<td><a href="#_01record-0f-a"><code>a</code></a> </td><td><span>A test field.</span></td></tr>
119+
</tbody>
120+
</table>
121+
122+
123+
124+
</div>
125+
<div>
126+
<div>
127+
<h2 id="_01record-0f-a"><a href="#_01record-0f-a">::a</a></h2>
128+
<div>
129+
<span>A test field.</span>
130+
131+
</div>
132+
</div>
133+
<div>
134+
<h3>Synopsis</h3>
135+
<div>
136+
Declared in <code>&lt;unnamed.cpp&gt;</code></div>
137+
<pre>
138+
<code class="source-code cpp">int a;
139+
140+
</code>
141+
</pre>
142+
</div>
25143
</div>
26144
<div>
27145
<div>
@@ -32,7 +150,47 @@ <h3>Synopsis</h3>
32150
<div>
33151
Declared in <code>&lt;unnamed.cpp&gt;</code></div>
34152
<pre>
35-
<code class="source-code cpp">constexpr /* implementation-defined */ F = {};
153+
<code class="source-code cpp">constexpr <a href="#_01record-01"></a> F = {};
154+
155+
</code>
156+
</pre>
157+
</div>
158+
</div>
159+
<div>
160+
<div>
161+
<h2 id="x"><a href="#x">x</a></h2>
162+
<div>
163+
<span>A test variable named &#x27;x&#x27;</span>
164+
165+
</div>
166+
</div>
167+
<div>
168+
<h3>Synopsis</h3>
169+
<div>
170+
Declared in <code>&lt;unnamed.cpp&gt;</code></div>
171+
<pre>
172+
<code class="source-code cpp">extern
173+
<a href="#_01record-0f"></a> x;
174+
175+
</code>
176+
</pre>
177+
</div>
178+
</div>
179+
<div>
180+
<div>
181+
<h2 id="y"><a href="#y">y</a></h2>
182+
<div>
183+
<span>A test variable named &#x27;y&#x27;</span>
184+
185+
</div>
186+
</div>
187+
<div>
188+
<h3>Synopsis</h3>
189+
<div>
190+
Declared in <code>&lt;unnamed.cpp&gt;</code></div>
191+
<pre>
192+
<code class="source-code cpp">extern
193+
<a href="#_01record-0f"></a> y;
36194

37195
</code>
38196
</pre>

0 commit comments

Comments
 (0)