llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Aydın Mercan (aydinmercan)

<details>
<summary>Changes</summary>

The clang AST now correctly matches trailing Doxygen comments for function 
declarations and also comments that come after the declaration with the same 
`&lt;` trailing directive.

---
Full diff: https://github.com/llvm/llvm-project/pull/198534.diff


1 Files Affected:

- (modified) clang/lib/AST/ASTContext.cpp (+12-5) 


``````````diff
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index bc4771aec77d1..fc2048239ba55 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -243,13 +243,20 @@ RawComment *ASTContext::getRawCommentForDeclNoCacheImpl(
          LangOpts.CommentOpts.ParseAllComments) &&
         CommentBehindDecl->isTrailingComment() &&
         (isa<FieldDecl>(D) || isa<EnumConstantDecl>(D) || isa<VarDecl>(D) ||
-         isa<ObjCMethodDecl>(D) || isa<ObjCPropertyDecl>(D))) {
+         isa<ObjCMethodDecl>(D) || isa<ObjCPropertyDecl>(D) ||
+         isa<FunctionDecl>(D))) {
 
-      // Check that Doxygen trailing comment comes after the declaration, 
starts
-      // on the same line and in the same file as the declaration.
-      if (SourceMgr.getLineNumber(DeclLocDecomp.first, DeclLocDecomp.second) ==
+      const auto DeclLineNumber =
+          SourceMgr.getLineNumber(DeclLocDecomp.first, DeclLocDecomp.second);
+
+      const auto DeclOfCommentLine =
           Comments.getCommentBeginLine(CommentBehindDecl, DeclLocDecomp.first,
-                                       OffsetCommentBehindDecl->first)) {
+                                       OffsetCommentBehindDecl->first);
+
+      // Check that Doxygen trailing comment comes after the declaration, 
starts
+      // on the same or next line and in the same file as the declaration.
+      if (DeclLineNumber == std::clamp(DeclLineNumber, DeclOfCommentLine,
+                                       DeclOfCommentLine + 1)) {
         return CommentBehindDecl;
       }
     }

``````````

</details>


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

Reply via email to