rymiel created this revision. rymiel added a project: clang-format. rymiel added reviewers: HazardyKnusperkeks, owenpan, MyDeveloperDay. Herald added projects: All, clang. Herald added a subscriber: cfe-commits. rymiel requested review of this revision.
This check is similar to the right paren check right below it, but it doesn't need the overloaded operator check. This patch prevents brace-initialized objects that are being compared from being mis-annotated as template parameters. Fixes https://github.com/llvm/llvm-project/issues/57004 Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D150629 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 @@ -10679,6 +10679,7 @@ // Not template parameters. verifyFormat("return a < b && c > d;"); verifyFormat("a < 0 ? b : a > 0 ? c : d;"); + verifyFormat("ratio{-1, 2} < ratio{-1, 3} == -1 / 3 > -1 / 2;"); verifyFormat("void f() {\n" " while (a < b && c > d) {\n" " }\n" Index: clang/lib/Format/TokenAnnotator.cpp =================================================================== --- clang/lib/Format/TokenAnnotator.cpp +++ clang/lib/Format/TokenAnnotator.cpp @@ -144,6 +144,8 @@ if (Previous.Previous) { if (Previous.Previous->Tok.isLiteral()) return false; + if (Previous.Previous->is(tok::r_brace)) + return false; if (Previous.Previous->is(tok::r_paren) && Contexts.size() > 1 && (!Previous.Previous->MatchingParen || !Previous.Previous->MatchingParen->is(
Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -10679,6 +10679,7 @@ // Not template parameters. verifyFormat("return a < b && c > d;"); verifyFormat("a < 0 ? b : a > 0 ? c : d;"); + verifyFormat("ratio{-1, 2} < ratio{-1, 3} == -1 / 3 > -1 / 2;"); verifyFormat("void f() {\n" " while (a < b && c > d) {\n" " }\n" Index: clang/lib/Format/TokenAnnotator.cpp =================================================================== --- clang/lib/Format/TokenAnnotator.cpp +++ clang/lib/Format/TokenAnnotator.cpp @@ -144,6 +144,8 @@ if (Previous.Previous) { if (Previous.Previous->Tok.isLiteral()) return false; + if (Previous.Previous->is(tok::r_brace)) + return false; if (Previous.Previous->is(tok::r_paren) && Contexts.size() > 1 && (!Previous.Previous->MatchingParen || !Previous.Previous->MatchingParen->is(
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits