From: Emilia Dreamer Date: Sat, 1 Oct 2022 05:16:45 +0000 (+0300) Subject: [clang-format] Correctly indent closing brace of compound requires X-Git-Tag: upstream/17.0.6~31891 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1fa115b569797f64988f3d8ddd8baa05574aafa3;p=platform%2Fupstream%2Fllvm.git [clang-format] Correctly indent closing brace of compound requires When a compound requirement is too long to fit onto a single line, the braces are split apart onto separate lines, and the contained expression is indented. However, this indentation would also apply to the closing brace and the trailing return type requirement thereof. This was because the indentation level was being restored after all trailing things were already read With this change, the initial level of the opening brace is set before attempting to read any trailing return type requirements Fixes https://github.com/llvm/llvm-project/issues/57108 Reviewed By: HazardyKnusperkeks, owenpan, MyDeveloperDay Differential Revision: https://reviews.llvm.org/D134626 --- diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index ead3f7f..f39c107 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -964,6 +964,8 @@ FormatToken *UnwrappedLineParser::parseBlock( if (MacroBlock && FormatTok->is(tok::l_paren)) parseParens(); + Line->Level = InitialLevel; + if (FormatTok->is(tok::kw_noexcept)) { // A noexcept in a requires expression. nextToken(); @@ -979,8 +981,6 @@ FormatToken *UnwrappedLineParser::parseBlock( if (MunchSemi && FormatTok->is(tok::semi)) nextToken(); - Line->Level = InitialLevel; - if (PPStartHash == PPEndHash) { Line->MatchingOpeningBlockLineIndex = OpeningLineIndex; if (OpeningLineIndex != UnwrappedLine::kInvalidIndex) { diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 9a1396b..fd567be 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -24510,6 +24510,16 @@ TEST_F(FormatTest, Concepts) { " { x * 1 } -> std::convertible_to;\n" " };"); + verifyFormat("template \n" + "concept C = requires(T x) {\n" + " {\n" + " long_long_long_function_call(1, 2, 3, 4, 5)\n" + " } -> long_long_concept_name;\n" + " {\n" + " long_long_long_function_call(1, 2, 3, 4, 5)\n" + " } noexcept -> long_long_concept_name;\n" + " };"); + verifyFormat( "template \n" "concept Swappable = requires(T &&t, U &&u) {\n"