https://github.com/evelez7 created 
https://github.com/llvm/llvm-project/pull/174883

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

>From da562758d6b659e1f0a3bd708f8e092d76e29c87 Mon Sep 17 00:00:00 2001
From: Erick Velez <[email protected]>
Date: Wed, 7 Jan 2026 14:22:28 -0800
Subject: [PATCH] [clang-doc] Add protected members to class template

There were already tags for protected members in the Mustache template,
but didn't use the proper tags for the newer JSON scheme.
---
 clang-tools-extra/clang-doc/JSONGenerator.cpp |  2 +-
 .../clang-doc/assets/class-template.mustache  | 23 ++++++++-----------
 .../test/clang-doc/json/class.cpp             |  9 ++++++++
 .../unittests/clang-doc/JSONGeneratorTest.cpp |  1 +
 4 files changed, 20 insertions(+), 15 deletions(-)

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,

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to