[PATCH] D150629: [clang-format] Don't allow template to be preceded by closing brace
Emilia Kond via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon May 15 18:23:02 PDT 2023
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(
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D150629.522403.patch
Type: text/x-patch
Size: 1067 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230516/8823b3f6/attachment.bin>
More information about the cfe-commits
mailing list