rymiel created this revision. rymiel added reviewers: HazardyKnusperkeks, owenpan, MyDeveloperDay, curdeius. Herald added a project: All. rymiel requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
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 Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D134626 Files: clang/lib/Format/UnwrappedLineParser.cpp clang/unittests/Format/FormatTest.cpp Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -24418,6 +24418,16 @@ " { x * 1 } -> std::convertible_to<T>;\n" " };"); + verifyFormat("template <typename T>\n" + "concept C = requires(T x) {\n" + " {\n" + " long_long_long_function_call(1, 2, 3, 4, 5)\n" + " } -> long_long_concept_name<T>;\n" + " {\n" + " long_long_long_function_call(1, 2, 3, 4, 5)\n" + " } noexcept -> long_long_concept_name<T>;\n" + " };"); + verifyFormat( "template <typename T, typename U = T>\n" "concept Swappable = requires(T &&t, U &&u) {\n" Index: clang/lib/Format/UnwrappedLineParser.cpp =================================================================== --- clang/lib/Format/UnwrappedLineParser.cpp +++ clang/lib/Format/UnwrappedLineParser.cpp @@ -964,6 +964,8 @@ 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 @@ if (MunchSemi && FormatTok->is(tok::semi)) nextToken(); - Line->Level = InitialLevel; - if (PPStartHash == PPEndHash) { Line->MatchingOpeningBlockLineIndex = OpeningLineIndex; if (OpeningLineIndex != UnwrappedLine::kInvalidIndex) {
Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -24418,6 +24418,16 @@ " { x * 1 } -> std::convertible_to<T>;\n" " };"); + verifyFormat("template <typename T>\n" + "concept C = requires(T x) {\n" + " {\n" + " long_long_long_function_call(1, 2, 3, 4, 5)\n" + " } -> long_long_concept_name<T>;\n" + " {\n" + " long_long_long_function_call(1, 2, 3, 4, 5)\n" + " } noexcept -> long_long_concept_name<T>;\n" + " };"); + verifyFormat( "template <typename T, typename U = T>\n" "concept Swappable = requires(T &&t, U &&u) {\n" Index: clang/lib/Format/UnwrappedLineParser.cpp =================================================================== --- clang/lib/Format/UnwrappedLineParser.cpp +++ clang/lib/Format/UnwrappedLineParser.cpp @@ -964,6 +964,8 @@ 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 @@ if (MunchSemi && FormatTok->is(tok::semi)) nextToken(); - Line->Level = InitialLevel; - if (PPStartHash == PPEndHash) { Line->MatchingOpeningBlockLineIndex = OpeningLineIndex; if (OpeningLineIndex != UnwrappedLine::kInvalidIndex) {
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits