diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index bc5239209f3aa..49482973223c6 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -3901,6 +3901,11 @@ bool TokenAnnotator::mustBreakForReturnType(const AnnotatedLine &Line) const { } void TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) const { + if (Line.Computed) + return; + + Line.Computed = true; + for (AnnotatedLine *ChildLine : Line.Children) calculateFormattingInformation(*ChildLine); diff --git a/clang/lib/Format/TokenAnnotator.h b/clang/lib/Format/TokenAnnotator.h index 5a02030e5ba7f..9117ca3f9fb7b 100644 --- a/clang/lib/Format/TokenAnnotator.h +++ b/clang/lib/Format/TokenAnnotator.h @@ -182,6 +182,9 @@ class AnnotatedLine { /// \c True if this line contains a macro call for which an expansion exists. bool ContainsMacroCall = false; + /// \c True if calculateFormattingInformation() has been called on this line. + bool Computed = false; + /// \c True if this line should be formatted, i.e. intersects directly or /// indirectly with one of the input ranges. bool Affected; diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 250e51b542166..63d8dc2486e45 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -27386,6 +27386,13 @@ TEST_F(FormatTest, RemoveSemicolon) { Style); #endif + verifyFormat("auto sgf = [] {\n" + " ogl = {\n" + " a, b, c, d, e,\n" + " };\n" + "};", + Style); + Style.TypenameMacros.push_back("STRUCT"); verifyFormat("STRUCT(T, B) { int i; };", Style); }