[clang-doc] Add protected members to class template#174883
Merged
Conversation
There were already tags for protected members in the Mustache template, but didn't use the proper tags for the newer JSON scheme.
Member
Author
Member
|
@llvm/pr-subscribers-clang-tools-extra Author: Erick Velez (evelez7) ChangesThere were already tags for protected members in the Mustache template, Full diff: https://github.com/llvm/llvm-project/pull/174883.diff 4 Files Affected:
diff --git a/clang-tools-extra/clang-doc/JSONGenerator.cpp b/clang-tools-extra/clang-doc/JSONGenerator.cpp
index 2dbc4186a32cc..fab54591b8faa 100644
--- a/clang-tools-extra/clang-doc/JSONGenerator.cpp
+++ b/clang-tools-extra/clang-doc/JSONGenerator.cpp
@@ -657,7 +657,7 @@ static void serializeInfo(const RecordInfo &I, json::Object &Obj,
if (!PubMembersArrayRef.empty())
insertArray(Obj, PublicMembersArray, "PublicMembers");
if (!ProtMembersArrayRef.empty())
- Obj["ProtectedMembers"] = ProtectedMembersArray;
+ insertArray(Obj, ProtectedMembersArray, "ProtectedMembers");
if (!PrivateMembersArrayRef.empty())
insertArray(Obj, PrivateMembersArray, "PrivateMembers");
}
diff --git a/clang-tools-extra/clang-doc/assets/class-template.mustache b/clang-tools-extra/clang-doc/assets/class-template.mustache
index 498fc5f079901..19e6e6adf1b44 100644
--- a/clang-tools-extra/clang-doc/assets/class-template.mustache
+++ b/clang-tools-extra/clang-doc/assets/class-template.mustache
@@ -31,22 +31,22 @@
</details>
</li>
{{/HasPublicMembers}}
- {{#ProtectedMembers}}
+ {{#HasProtectedMembers}}
<li>
<details open>
<summary class="sidebar-section">
- <a class="sidebar-item" href="#PublicMethods">Protected Members</a>
+ <a class="sidebar-item" href="#ProtectedMembers">Protected Members</a>
</summary>
<ul>
- {{#Obj}}
+ {{#ProtectedMembers}}
<li class="sidebar-item-container">
<a class="sidebar-item" href="#{{Name}}">{{Name}}</a>
</li>
- {{/Obj}}
+ {{/ProtectedMembers}}
</ul>
</details>
</li>
- {{/ProtectedMembers}}
+ {{/HasProtectedMembers}}
{{#HasPublicFunctions}}
<li>
<details open>
@@ -178,23 +178,18 @@
</div>
</section>
{{/HasPublicMembers}}
- {{#ProtectedMembers}}
+ {{#HasProtectedMembers}}
<section id="ProtectedMembers" class="section-container">
<h2>Protected Members</h2>
<div>
- {{#Obj}}
+ {{#ProtectedMembers}}
<div id="{{Name}}" class="delimiter-container">
<pre><code class="language-cpp code-clang-doc" >{{#IsStatic}}static {{/IsStatic}}{{Type}} {{Name}}</code></pre>
- {{#MemberComments}}
- <div>
- {{>Comments}}
- </div>
- {{/MemberComments}}
</div>
- {{/Obj}}
+ {{/ProtectedMembers}}
</div>
</section>
- {{/ProtectedMembers}}
+ {{/HasProtectedMembers}}
{{#HasPublicFunctions}}
<section id="PublicMethods" class="section-container">
<h2>Public Methods</h2>
diff --git a/clang-tools-extra/test/clang-doc/json/class.cpp b/clang-tools-extra/test/clang-doc/json/class.cpp
index 9b45f86ff3292..6356aee14c16c 100644
--- a/clang-tools-extra/test/clang-doc/json/class.cpp
+++ b/clang-tools-extra/test/clang-doc/json/class.cpp
@@ -170,6 +170,7 @@ struct MyClass {
// CHECK-NEXT: "HasEnums": true,
// CHECK-NEXT: "HasFriends": true,
// CHECK-NEXT: "HasPrivateMembers": true,
+// CHECK-NEXT: "HasProtectedMembers": true,
// CHECK-NEXT: "HasPublicFunctions": true,
// CHECK-NEXT: "HasPublicMembers": true,
// CHECK-NEXT: "HasRecords": true,
@@ -320,6 +321,14 @@ struct MyClass {
// HTML-NEXT: </li>
// HTML-NEXT: </ul>
// HTML-NEXT: </details>
+// HTML: <section id="ProtectedMembers" class="section-container">
+// HTML-NEXT: <h2>Protected Members</h2>
+// HTML-NEXT: <div>
+// HTML-NEXT: <div id="ProtectedField" class="delimiter-container">
+// HTML-NEXT: <pre><code class="language-cpp code-clang-doc" >int ProtectedField</code></pre>
+// HTML-NEXT: </div>
+// HTML-NEXT: </div>
+// HTML-NEXT: </section>
// HTML: <section id="Classes" class="section-container">
// HTML-NEXT: <h2>Inner Classes</h2>
// HTML-NEXT: <ul class="class-container">
diff --git a/clang-tools-extra/unittests/clang-doc/JSONGeneratorTest.cpp b/clang-tools-extra/unittests/clang-doc/JSONGeneratorTest.cpp
index ee2c11061d706..d4260ebae3123 100644
--- a/clang-tools-extra/unittests/clang-doc/JSONGeneratorTest.cpp
+++ b/clang-tools-extra/unittests/clang-doc/JSONGeneratorTest.cpp
@@ -117,6 +117,7 @@ TEST_F(JSONGeneratorTest, emitRecordJSON) {
],
"HasEnums": true,
"HasParents": true,
+ "HasProtectedMembers": true,
"HasPublicFunctions": true,
"HasRecords": true,
"HasVirtualParents": true,
|
Member
Author
Member
Author
kshitijvp
pushed a commit
to kshitijvp/llvm-project
that referenced
this pull request
Jan 9, 2026
There were already tags for protected members in the Mustache template, but didn't use the proper tags for the newer JSON scheme.
Priyanshu3820
pushed a commit
to Priyanshu3820/llvm-project
that referenced
this pull request
Jan 18, 2026
There were already tags for protected members in the Mustache template, but didn't use the proper tags for the newer JSON scheme.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

There were already tags for protected members in the Mustache template,
but didn't use the proper tags for the newer JSON scheme.