Skip to content

identify duplicate and excluded friends #944

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/lib/AST/ASTVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,24 @@ populate(
}
FriendInfo F;
populate(F, FD);
I.Friends.push_back(std::move(F));
if (F.id != SymbolID::invalid)
{
Info* FI = this->find(F.id);
MRDOCS_CHECK_OR_CONTINUE(FI);
MRDOCS_CHECK_OR_CONTINUE(FI->Extraction != ExtractionMode::ImplementationDefined);
}
auto it = std::ranges::find_if(I.Friends, [&](FriendInfo const& FI)
{
return FI.id == F.id;
});
if (it != I.Friends.end())
{
merge(*it, std::move(F));
}
else
{
I.Friends.push_back(std::move(F));
}
}
}
}
Expand Down
74 changes: 74 additions & 0 deletions test-files/golden-tests/symbols/record/friend-duplicate.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
= Reference
:mrdocs:

[#index]
== Global namespace

=== Types

[cols=1]
|===
| Name
| link:#A[`A`]
| link:#B[`B`]
|===

=== Functions

[cols=1]
|===
| Name
| link:#f[`f`]
|===

[#A]
== A

=== Synopsis

Declared in `<friend‐duplicate.cpp>`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
class A;
----

=== Friends

[cols=2]
|===
| Name
| Description
| `link:#f[f]`
|
| `link:#B[B]`
|
|===

[#B]
== B

=== Synopsis

Declared in `<friend‐duplicate.cpp>`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
class B;
----

[#f]
== f

=== Synopsis

Declared in `<friend‐duplicate.cpp>`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
void
f();
----


[.small]#Created with https://www.mrdocs.com[MrDocs]#
14 changes: 14 additions & 0 deletions test-files/golden-tests/symbols/record/friend-duplicate.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class A
{
friend class B;
friend class B;
friend class B;

friend void f();
friend void f();
friend void f();
};

class B {};

void f();
118 changes: 118 additions & 0 deletions test-files/golden-tests/symbols/record/friend-duplicate.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
<html lang="en">
<head>
<title>Reference</title>
</head>
<body>
<div>
<h1>Reference</h1>
<div>
<div>
<h2 id="index"><a href="#index"></a></h2>
</div>
<h2>Types</h2>
<table style="table-layout: fixed; width: 100%;">
<thead>
<tr>
<th>Name</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="#A"><code>A</code></a> </td></tr><tr>
<td><a href="#B"><code>B</code></a> </td></tr>
</tbody>
</table>

<h2>Functions</h2>
<table style="table-layout: fixed; width: 100%;">
<thead>
<tr>
<th>Name</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="#f"><code>f</code></a> </td></tr>
</tbody>
</table>

</div>
<div>
<div>
<h2 id="A"><a href="#A">A</a></h2>
</div>
<div>
<h3>Synopsis</h3>
<div>
Declared in <code>&lt;friend-duplicate.cpp&gt;</code></div>
<pre>
<code class="source-code cpp">
class A;
</code>
</pre>
</div>


<div>
<h2>Friends</h2>
<table>
<thead>
<tr>
<th>Name</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code><a href="#f">f</a></code></td>
<td><span></span></td>
</tr>
<tr>
<td><code><a href="#B">B</a></code></td>
<td><span></span></td>
</tr>
|===
</tbody>
</table>
</div>
</div>
<div>
<div>
<h2 id="B"><a href="#B">B</a></h2>
</div>
<div>
<h3>Synopsis</h3>
<div>
Declared in <code>&lt;friend-duplicate.cpp&gt;</code></div>
<pre>
<code class="source-code cpp">
class B;
</code>
</pre>
</div>


</div>
<div>
<div>
<h2 id="f"><a href="#f">f</a></h2>
</div>
<div>
<h3>Synopsis</h3>
<div>
Declared in <code>&lt;friend-duplicate.cpp&gt;</code></div>
<pre>
<code class="source-code cpp">
void
f();
</code>
</pre>
</div>
</div>

</div>
<div>
<h4>Created with <a href="https://www.mrdocs.com">MrDocs</a></h4>
</div>
</body>
</html>
24 changes: 24 additions & 0 deletions test-files/golden-tests/symbols/record/friend-duplicate.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<mrdocs xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://github.com/cppalliance/mrdocs/raw/develop/mrdocs.rnc">
<namespace id="//////////////////////////8=">
<class name="A" id="YrPSaKAbmXgzCAX5WByx4eVoqBM=">
<file short-path="friend-duplicate.cpp" source-path="friend-duplicate.cpp" line="1" class="def"/>
<friend id="s6nsa+zVhpzzrN+yUVPP5rvdXqs=">
<befriended id="s6nsa+zVhpzzrN+yUVPP5rvdXqs="/>
</friend>
<friend id="3JsK1DO0O+wZhv+0meptQrbs3fY=">
<befriended id="3JsK1DO0O+wZhv+0meptQrbs3fY="/>
</friend>
</class>
<class name="B" id="3JsK1DO0O+wZhv+0meptQrbs3fY=">
<file short-path="friend-duplicate.cpp" source-path="friend-duplicate.cpp" line="12" class="def"/>
</class>
<function name="f" id="s6nsa+zVhpzzrN+yUVPP5rvdXqs=">
<file short-path="friend-duplicate.cpp" source-path="friend-duplicate.cpp" line="9"/>
<file short-path="friend-duplicate.cpp" source-path="friend-duplicate.cpp" line="8"/>
<file short-path="friend-duplicate.cpp" source-path="friend-duplicate.cpp" line="7"/>
<file short-path="friend-duplicate.cpp" source-path="friend-duplicate.cpp" line="14"/>
</function>
</namespace>
</mrdocs>
74 changes: 74 additions & 0 deletions test-files/golden-tests/symbols/record/friend-excluded.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
= Reference
:mrdocs:

[#index]
== Global namespace

=== Types

[cols=1]
|===
| Name
| link:#A[`A`]
| link:#B[`B`]
|===

=== Functions

[cols=1]
|===
| Name
| link:#f[`f`]
|===

[#A]
== A

=== Synopsis

Declared in `&lt;friend&hyphen;excluded&period;cpp&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
class A;
----

=== Friends

[cols=2]
|===
| Name
| Description
| `link:#f[f]`
|
| `link:#B[B]`
|
|===

[#B]
== B

=== Synopsis

Declared in `&lt;friend&hyphen;excluded&period;cpp&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
class B;
----

[#f]
== f

=== Synopsis

Declared in `&lt;friend&hyphen;excluded&period;cpp&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
void
f();
----


[.small]#Created with https://www.mrdocs.com[MrDocs]#
14 changes: 14 additions & 0 deletions test-files/golden-tests/symbols/record/friend-excluded.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace detail {
class impl;
}

class B {};

void f();

class A
{
friend class detail::impl;
friend class B;
friend void f();
};
Loading
Loading