[clang-tools-extra] [clang-doc] Flatten repeated @return and @brief comment arrays (PR #188739)
Paul Kirth via cfe-commits
cfe-commits at lists.llvm.org
Fri Apr 3 13:45:21 PDT 2026
================
@@ -150,11 +153,26 @@ static void insertComment(Object &Description, json::Value &Comment,
auto DescriptionIt = Description.find(Key);
if (DescriptionIt == Description.end()) {
- auto CommentsArray = json::Array();
- CommentsArray.push_back(Comment);
- Description[Key] = std::move(CommentsArray);
+ // For FlattenArray mode, if Comment is an array, use it directly
+ if (FlattenArray && Comment.getAsArray()) {
+ Description[Key] = Comment;
+ } else {
+ auto CommentsArray = json::Array();
+ CommentsArray.push_back(Comment);
+ Description[Key] = std::move(CommentsArray);
+ }
Description["Has" + Key.str()] = true;
} else {
+ // For FlattenArray mode, if Comment is an array, merge its elements
+ if (FlattenArray) {
+ if (auto *CommentArray = Comment.getAsArray()) {
+ auto *DestArray = DescriptionIt->getSecond().getAsArray();
----------------
ilovepi wrote:
If you're going to get a reference to this here and its used below, then hoist that out of the conditional and don't recalculate it or rely on the compiler to fold it away. Also, since you're dereffing it take a reference. otherwise you need to have some kind of validity check on the pointer value.
https://github.com/llvm/llvm-project/pull/188739
More information about the cfe-commits
mailing list