diff options
author | Björn Schäpers <bjoern@hazardy.de> | 2022-11-18 07:31:06 +0100 |
---|---|---|
committer | Björn Schäpers <bjoern@hazardy.de> | 2023-08-02 11:50:14 +0200 |
commit | 77a38f43b168e5c2a9395ab4c2bd1479a297ade5 (patch) | |
tree | 53477abe3d7a46f36dee96cfa110cd7e2c3a6853 /clang/lib/Format/WhitespaceManager.cpp | |
parent | 8acb8a143f5075cf8f9ff0818e89b1f80827f0e9 (diff) | |
download | llvm-77a38f43b168e5c2a9395ab4c2bd1479a297ade5.zip llvm-77a38f43b168e5c2a9395ab4c2bd1479a297ade5.tar.gz llvm-77a38f43b168e5c2a9395ab4c2bd1479a297ade5.tar.bz2 |
[clang-format] Supress aligning of trailing namespace comments
Fixes https://github.com/llvm/llvm-project/issues/57504.
Differential Revision: https://reviews.llvm.org/D138263
Diffstat (limited to 'clang/lib/Format/WhitespaceManager.cpp')
-rw-r--r-- | clang/lib/Format/WhitespaceManager.cpp | 11 |
1 files changed, 5 insertions, 6 deletions
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; |