================ @@ -1118,16 +1121,35 @@ void WhitespaceManager::alignTrailingComments() { } } - // We don't want to align namespace end comments. - const bool DontAlignThisComment = - I > 0 && C.NewlinesBefore == 0 && - Changes[I - 1].Tok->is(TT_NamespaceRBrace); - if (Style.AlignTrailingComments.Kind == FormatStyle::TCAS_Never || - DontAlignThisComment) { + // We don't want to align comments which end a scope, which are here + // identified by most closing braces. + const bool DontAlignThisComment = [&] { + if (I == 0 || C.NewlinesBefore > 0) + return false; + const auto *Tok = Changes[I - 1].Tok; + if (Tok->is(tok::semi)) { + Tok = Tok->Previous; + if (!Tok) + return false; + } + if (Tok->isNot(tok::r_brace)) + return false; + auto LastBrace = Tok; + while (Tok->Previous && Tok->Previous->is(tok::r_brace)) + Tok = Tok->Previous; + return Tok->NewlinesBefore > 0 || + LastBrace->isOneOf(TT_ClassRBrace, TT_EnumRBrace, + TT_NamespaceRBrace, TT_StructRBrace, + TT_UnionRBrace); ---------------- owenca wrote:
Do we need the `||` part at all? For example, we would still want to align trailing comments of single-line `enum`s: ``` enum color { red, green, blue }; // enum season { spring, summer, fall, winter }; // ``` https://github.com/llvm/llvm-project/pull/68743 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits