Skip to content

Commit e4a4a15

Browse files
committed
fix: populating RecordInfo identifies duplicate friend IDs
fix #925
1 parent 502cfbd commit e4a4a15

File tree

5 files changed

+242
-1
lines changed

5 files changed

+242
-1
lines changed

src/lib/AST/ASTVisitor.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,18 @@ populate(
732732
}
733733
FriendInfo F;
734734
populate(F, FD);
735-
I.Friends.push_back(std::move(F));
735+
auto it = std::ranges::find_if(I.Friends, [&](FriendInfo const& FI)
736+
{
737+
return FI.id == F.id;
738+
});
739+
if (it != I.Friends.end())
740+
{
741+
merge(*it, std::move(F));
742+
}
743+
else
744+
{
745+
I.Friends.push_back(std::move(F));
746+
}
736747
}
737748
}
738749
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
= Reference
2+
:mrdocs:
3+
4+
[#index]
5+
== Global namespace
6+
7+
=== Types
8+
9+
[cols=1]
10+
|===
11+
| Name
12+
| link:#A[`A`]
13+
| link:#B[`B`]
14+
|===
15+
16+
=== Functions
17+
18+
[cols=1]
19+
|===
20+
| Name
21+
| link:#f[`f`]
22+
|===
23+
24+
[#A]
25+
== A
26+
27+
=== Synopsis
28+
29+
Declared in `<friend‐duplicate.cpp>`
30+
31+
[source,cpp,subs="verbatim,replacements,macros,-callouts"]
32+
----
33+
class A;
34+
----
35+
36+
=== Friends
37+
38+
[cols=2]
39+
|===
40+
| Name
41+
| Description
42+
| `link:#f[f]`
43+
|
44+
| `link:#B[B]`
45+
|
46+
|===
47+
48+
[#B]
49+
== B
50+
51+
=== Synopsis
52+
53+
Declared in `<friend‐duplicate.cpp>`
54+
55+
[source,cpp,subs="verbatim,replacements,macros,-callouts"]
56+
----
57+
class B;
58+
----
59+
60+
[#f]
61+
== f
62+
63+
=== Synopsis
64+
65+
Declared in `<friend‐duplicate.cpp>`
66+
67+
[source,cpp,subs="verbatim,replacements,macros,-callouts"]
68+
----
69+
void
70+
f();
71+
----
72+
73+
74+
[.small]#Created with https://www.mrdocs.com[MrDocs]#
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class A
2+
{
3+
friend class B;
4+
friend class B;
5+
friend class B;
6+
7+
friend void f();
8+
friend void f();
9+
friend void f();
10+
};
11+
12+
class B {};
13+
14+
void f();
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
<html lang="en">
2+
<head>
3+
<title>Reference</title>
4+
</head>
5+
<body>
6+
<div>
7+
<h1>Reference</h1>
8+
<div>
9+
<div>
10+
<h2 id="index"><a href="#index"></a></h2>
11+
</div>
12+
<h2>Types</h2>
13+
<table style="table-layout: fixed; width: 100%;">
14+
<thead>
15+
<tr>
16+
<th>Name</th>
17+
</tr>
18+
</thead>
19+
<tbody>
20+
<tr>
21+
<td><a href="#A"><code>A</code></a> </td></tr><tr>
22+
<td><a href="#B"><code>B</code></a> </td></tr>
23+
</tbody>
24+
</table>
25+
26+
<h2>Functions</h2>
27+
<table style="table-layout: fixed; width: 100%;">
28+
<thead>
29+
<tr>
30+
<th>Name</th>
31+
</tr>
32+
</thead>
33+
<tbody>
34+
<tr>
35+
<td><a href="#f"><code>f</code></a> </td></tr>
36+
</tbody>
37+
</table>
38+
39+
</div>
40+
<div>
41+
<div>
42+
<h2 id="A"><a href="#A">A</a></h2>
43+
</div>
44+
<div>
45+
<h3>Synopsis</h3>
46+
<div>
47+
Declared in <code>&lt;friend-duplicate.cpp&gt;</code></div>
48+
<pre>
49+
<code class="source-code cpp">
50+
class A;
51+
</code>
52+
</pre>
53+
</div>
54+
55+
56+
<div>
57+
<h2>Friends</h2>
58+
<table>
59+
<thead>
60+
<tr>
61+
<th>Name</th>
62+
<th>Description</th>
63+
</tr>
64+
</thead>
65+
<tbody>
66+
<tr>
67+
<td><code><a href="#f">f</a></code></td>
68+
<td><span></span></td>
69+
</tr>
70+
<tr>
71+
<td><code><a href="#B">B</a></code></td>
72+
<td><span></span></td>
73+
</tr>
74+
|===
75+
</tbody>
76+
</table>
77+
</div>
78+
</div>
79+
<div>
80+
<div>
81+
<h2 id="B"><a href="#B">B</a></h2>
82+
</div>
83+
<div>
84+
<h3>Synopsis</h3>
85+
<div>
86+
Declared in <code>&lt;friend-duplicate.cpp&gt;</code></div>
87+
<pre>
88+
<code class="source-code cpp">
89+
class B;
90+
</code>
91+
</pre>
92+
</div>
93+
94+
95+
</div>
96+
<div>
97+
<div>
98+
<h2 id="f"><a href="#f">f</a></h2>
99+
</div>
100+
<div>
101+
<h3>Synopsis</h3>
102+
<div>
103+
Declared in <code>&lt;friend-duplicate.cpp&gt;</code></div>
104+
<pre>
105+
<code class="source-code cpp">
106+
void
107+
f();
108+
</code>
109+
</pre>
110+
</div>
111+
</div>
112+
113+
</div>
114+
<div>
115+
<h4>Created with <a href="https://www.mrdocs.com">MrDocs</a></h4>
116+
</div>
117+
</body>
118+
</html>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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 id="//////////////////////////8=">
5+
<class name="A" id="YrPSaKAbmXgzCAX5WByx4eVoqBM=">
6+
<file short-path="friend-duplicate.cpp" source-path="friend-duplicate.cpp" line="1" class="def"/>
7+
<friend id="s6nsa+zVhpzzrN+yUVPP5rvdXqs=">
8+
<befriended id="s6nsa+zVhpzzrN+yUVPP5rvdXqs="/>
9+
</friend>
10+
<friend id="3JsK1DO0O+wZhv+0meptQrbs3fY=">
11+
<befriended id="3JsK1DO0O+wZhv+0meptQrbs3fY="/>
12+
</friend>
13+
</class>
14+
<class name="B" id="3JsK1DO0O+wZhv+0meptQrbs3fY=">
15+
<file short-path="friend-duplicate.cpp" source-path="friend-duplicate.cpp" line="12" class="def"/>
16+
</class>
17+
<function name="f" id="s6nsa+zVhpzzrN+yUVPP5rvdXqs=">
18+
<file short-path="friend-duplicate.cpp" source-path="friend-duplicate.cpp" line="9"/>
19+
<file short-path="friend-duplicate.cpp" source-path="friend-duplicate.cpp" line="8"/>
20+
<file short-path="friend-duplicate.cpp" source-path="friend-duplicate.cpp" line="7"/>
21+
<file short-path="friend-duplicate.cpp" source-path="friend-duplicate.cpp" line="14"/>
22+
</function>
23+
</namespace>
24+
</mrdocs>

0 commit comments

Comments
 (0)