rymiel created this revision. rymiel added reviewers: HazardyKnusperkeks, owenpan, MyDeveloperDay. Herald added a project: All. rymiel requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
This allows for `AlignAfterOpenBracket: BlockIndent` to work correctly when using values with type parameters. Line breaks after any template closer was disallowed 10 years ago, in 90e51fdbab33d43e0d4f932c2d90d0b86e865664, as a fix to https://github.com/llvm/llvm-project/issues/15158. Allowing it again, but only if preceding a specific character, seems to work out fine. Note that this change originally caused a test failure in `FormatTestJS.NoBreakAfterAsserts`, which is why there is an explicit negative check against `TT_JsTypeColon`. Given this, I'm not 100% confident in this change not producing defects, especially in other languages, but that was the only one in the test suite. Perhaps additional restrictions should be used, such as requiring `BAS_BlockIndent` to be set. Fixes https://github.com/llvm/llvm-project/issues/59567 Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D140267 Files: clang/lib/Format/TokenAnnotator.cpp clang/unittests/Format/FormatTest.cpp Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -24868,6 +24868,12 @@ "(\n" ") = nullptr;", Style); + + verifyFormat("static_assert(\n" + " std::is_base_of_v<std::output_iterator_tag, Category> ||\n" + " std::is_base_of_v<std::input_iterator_tag, Category>\n" + ");", + Style); } TEST_F(FormatTest, AlignAfterOpenBracketBlockIndentIfStatement) { Index: clang/lib/Format/TokenAnnotator.cpp =================================================================== --- clang/lib/Format/TokenAnnotator.cpp +++ clang/lib/Format/TokenAnnotator.cpp @@ -4952,6 +4952,10 @@ return false; if (Left.is(TT_TemplateCloser) && Right.is(TT_TemplateOpener)) return true; + if (Left.is(TT_TemplateCloser) && Right.is(tok::r_paren) && + (!Right.Next || Right.Next->isNot(TT_JsTypeColon))) { + return true; + } if ((Left.is(tok::greater) && Right.is(tok::greater)) || (Left.is(tok::less) && Right.is(tok::less))) { return false;
Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -24868,6 +24868,12 @@ "(\n" ") = nullptr;", Style); + + verifyFormat("static_assert(\n" + " std::is_base_of_v<std::output_iterator_tag, Category> ||\n" + " std::is_base_of_v<std::input_iterator_tag, Category>\n" + ");", + Style); } TEST_F(FormatTest, AlignAfterOpenBracketBlockIndentIfStatement) { Index: clang/lib/Format/TokenAnnotator.cpp =================================================================== --- clang/lib/Format/TokenAnnotator.cpp +++ clang/lib/Format/TokenAnnotator.cpp @@ -4952,6 +4952,10 @@ return false; if (Left.is(TT_TemplateCloser) && Right.is(TT_TemplateOpener)) return true; + if (Left.is(TT_TemplateCloser) && Right.is(tok::r_paren) && + (!Right.Next || Right.Next->isNot(TT_JsTypeColon))) { + return true; + } if ((Left.is(tok::greater) && Right.is(tok::greater)) || (Left.is(tok::less) && Right.is(tok::less))) { return false;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits