https://github.com/aydinmercan updated https://github.com/llvm/llvm-project/pull/198534
From 842ea11f48900453fb4ae9034da74621074ea314 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ayd=C4=B1n=20Mercan?= <[email protected]> Date: Thu, 30 Jul 2026 12:00:11 +0300 Subject: [PATCH] [clang] associate newline and function decl. trailing Doxygen comments The clang AST now correctly matches trailing Doxygen comments for function declarations and also comments that come after the declaration with the same `<` trailing directive. --- clang/lib/AST/ASTContext.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index 02a3f88431f58..8b5970690a65e 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -272,15 +272,20 @@ RawComment *ASTContext::getRawCommentNoCacheImpl( if ((CommentBehindDecl->isDocumentation() || LangOpts.CommentOpts.ParseAllComments) && CommentBehindDecl->isTrailingComment() && - (IsMacro || (D && (isa<FieldDecl>(D) || isa<EnumConstantDecl>(D) || - isa<VarDecl>(D) || isa<ObjCMethodDecl>(D) || - isa<ObjCPropertyDecl>(D))))) { + (IsMacro || + (D && (isa<FieldDecl>(D) || isa<EnumConstantDecl>(D) || + isa<VarDecl>(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(LocDecomp.first, LocDecomp.second) == - Comments.getCommentBeginLine(CommentBehindDecl, LocDecomp.first, - OffsetCommentBehindDecl->first)) { + // on the same or the next line, and in the same file as the declaration. + auto LocLineNumber = + SourceMgr.getLineNumber(LocDecomp.first, LocDecomp.second); + auto CommentBeginLine = Comments.getCommentBeginLine( + CommentBehindDecl, LocDecomp.first, OffsetCommentBehindDecl->first); + if (LocLineNumber == CommentBeginLine || + (LocLineNumber + 1 == CommentBeginLine && + CommentBehindDecl->isDocumentation())) { return CommentBehindDecl; } } _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
