From 77a38f43b168e5c2a9395ab4c2bd1479a297ade5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Sch=C3=A4pers?= Date: Fri, 18 Nov 2022 07:31:06 +0100 Subject: [clang-format] Supress aligning of trailing namespace comments Fixes https://github.com/llvm/llvm-project/issues/57504. Differential Revision: https://reviews.llvm.org/D138263 --- clang/lib/Format/WhitespaceManager.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'clang/lib/Format/WhitespaceManager.cpp') diff --git a/clang/lib/Format/WhitespaceManager.cpp b/clang/lib/Format/WhitespaceManager.cpp index 668ca38..61e59d0 100644 --- a/clang/lib/Format/WhitespaceManager.cpp +++ b/clang/lib/Format/WhitespaceManager.cpp @@ -1081,11 +1081,10 @@ void WhitespaceManager::alignTrailingComments() { if (i + 1 != e && Changes[i + 1].ContinuesPPDirective) ChangeMaxColumn -= 2; - // If this comment follows an } in column 0, it probably documents the - // closing of a namespace and we don't want to align it. - bool FollowsRBraceInColumn0 = i > 0 && Changes[i].NewlinesBefore == 0 && - Changes[i - 1].Tok->is(tok::r_brace) && - Changes[i - 1].StartOfTokenColumn == 0; + + // We don't want to align namespace end comments. + bool DontAlignThisComment = i > 0 && Changes[i].NewlinesBefore == 0 && + Changes[i - 1].Tok->is(TT_NamespaceRBrace); bool WasAlignedWithStartOfNextLine = false; if (Changes[i].NewlinesBefore >= 1) { // A comment on its own line. unsigned CommentColumn = SourceMgr.getSpellingColumnNumber( @@ -1105,7 +1104,7 @@ void WhitespaceManager::alignTrailingComments() { } } if (Style.AlignTrailingComments.Kind == FormatStyle::TCAS_Never || - FollowsRBraceInColumn0) { + DontAlignThisComment) { alignTrailingComments(StartOfSequence, i, MinColumn); MinColumn = ChangeMinColumn; MaxColumn = ChangeMinColumn; -- cgit v1.1