Skip to content

Commit 0e1e5f9

Browse files
committed
fix: prevent infinite recursion when extracting non-regular base class
A non-regular base class can have a member class which is a base class of the former. This fix prevents infinite recursion in this case.
1 parent c3dbded commit 0e1e5f9

File tree

7 files changed

+179
-17
lines changed

7 files changed

+179
-17
lines changed

include/mrdocs/Metadata/Symbol/SymbolBase.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ struct MRDOCS_VISIBLE Symbol {
7676
*/
7777
bool IsCopyFromInherited = false;
7878

79+
/** Whether this symbol was extracted as a base class of a symbol which
80+
* passes the filters.
81+
*/
82+
bool IsBaseClass = false;
83+
7984
/** The parent symbol, if any.
8085
8186
This is the parent namespace or record

src/lib/AST/ASTVisitor.cpp

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -677,25 +677,18 @@ populate(
677677
// isn’t regular so we pick up their members/docs.
678678
if (config_->inheritBaseMembers != PublicSettings::BaseMemberInheritance::Never)
679679
{
680-
if (auto const* baseDecl = BT->getAsCXXRecordDecl())
680+
if (auto const* baseDecl = BT->getAsCXXRecordDecl();
681+
baseDecl && baseDecl->isCompleteDefinition())
681682
{
682-
if (auto const* baseDef = baseDecl->getDefinition();
683-
baseDef)
683+
if (auto* baseInfo = find(baseDecl);
684+
!baseInfo
685+
|| (baseInfo->Extraction != ExtractionMode::Regular
686+
&& !baseInfo->IsBaseClass))
684687
{
685-
if (auto const* baseInfo = find(baseDef);
686-
baseInfo)
687-
{
688-
if (baseInfo->Extraction != ExtractionMode::Regular)
689-
{
690-
ScopeExitRestore s(mode_, TraversalMode::BaseClass);
691-
traverse(baseDef);
692-
}
693-
}
694-
else
695-
{
696-
ScopeExitRestore s(mode_, TraversalMode::BaseClass);
697-
traverse(baseDef);
698-
}
688+
ScopeExitRestore s(mode_, TraversalMode::BaseClass);
689+
if (baseInfo)
690+
baseInfo->IsBaseClass = true;
691+
traverse(baseDecl);
699692
}
700693
}
701694
}
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+
=== Namespaces
8+
9+
[cols=1]
10+
|===
11+
| Name
12+
| link:#fmt[`fmt`]
13+
|===
14+
15+
[#fmt]
16+
== fmt
17+
18+
=== Types
19+
20+
[cols=1]
21+
|===
22+
| Name
23+
| link:#fmt-path[`path`]
24+
|===
25+
26+
[#fmt-path]
27+
== link:#fmt[fmt]::path
28+
29+
=== Synopsis
30+
31+
Declared in `<forward‐declared‐member.cpp>`
32+
33+
[source,cpp,subs="verbatim,replacements,macros,-callouts"]
34+
----
35+
struct path
36+
: std::path
37+
----
38+
39+
=== Base Classes
40+
41+
[cols="1,4"]
42+
|===
43+
|Name|Description
44+
45+
| `std::path`
46+
|
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+
namespace std {
2+
class path {
3+
struct _Cmpt;
4+
};
5+
struct path::_Cmpt : path {};
6+
} // namespace std
7+
namespace fmt {
8+
struct path : std::path {};
9+
} // namespace fmt
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
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<a class="mrdocs-anchor" href="#index" aria-label="Permalink">#</a>
13+
</h2>
14+
</div>
15+
<h2>
16+
Namespaces</h2>
17+
<table style="table-layout: fixed; width: 100%;">
18+
<thead>
19+
<tr>
20+
<th>Name</th>
21+
</tr>
22+
</thead>
23+
<tbody>
24+
<tr>
25+
<td><a href="#fmt"><code>fmt</code></a> </td></tr>
26+
</tbody>
27+
</table>
28+
29+
</div>
30+
<div>
31+
<div>
32+
<h2 id="fmt">
33+
fmt<a class="mrdocs-anchor" href="#fmt" aria-label="Permalink">#</a>
34+
</h2>
35+
</div>
36+
<h2>
37+
Types</h2>
38+
<table style="table-layout: fixed; width: 100%;">
39+
<thead>
40+
<tr>
41+
<th>Name</th>
42+
</tr>
43+
</thead>
44+
<tbody>
45+
<tr>
46+
<td><a href="#fmt-path"><code>path</code></a> </td></tr>
47+
</tbody>
48+
</table>
49+
50+
</div>
51+
<div>
52+
<div>
53+
<h2 id="fmt-path">
54+
fmt::path<a class="mrdocs-anchor" href="#fmt-path" aria-label="Permalink">#</a>
55+
</h2>
56+
</div>
57+
<div>
58+
<h3>
59+
Synopsis</h3>
60+
<div>
61+
Declared in <code>&lt;forward-declared-member.cpp&gt;</code></div>
62+
<pre><code class="source-code cpp">struct path
63+
: std::path</code></pre>
64+
</div>
65+
<div>
66+
<h2>
67+
Base Classes</h2>
68+
<table>
69+
<thead>
70+
<tr>
71+
<th>Name</th>
72+
<th>Description</th>
73+
</tr>
74+
</thead>
75+
<tbody>
76+
<tr><td><code>std::path</code></td><td></td></tr>
77+
</tbody>
78+
</table>
79+
</div>
80+
81+
82+
</div>
83+
84+
</div>
85+
<footer class="mrdocs-footer">
86+
<span>Created with <a href="https://www.mrdocs.com">MrDocs</a></span>
87+
</footer>
88+
</body>
89+
</html>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+
<namespace name="fmt" id="csn+vnio1BK5NeCdEBf/HpD6wmY=">
6+
<struct name="path" id="5RffQbxkZ8sUj37sDwK63dA5ptA=">
7+
<file short-path="forward-declared-member.cpp" source-path="forward-declared-member.cpp" line="8" class="def"/>
8+
<base>
9+
<type id="ufjqSG34/fsb1/dKE4dBgs8spHM=" name="std::path"/>
10+
</base>
11+
</struct>
12+
</namespace>
13+
</namespace>
14+
</mrdocs>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
include-symbols:
2+
- 'fmt::**'

0 commit comments

Comments
 (0)