[PATCH] D140843: [clang-format] fix template closer followed by >
Zhikai Zeng via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Jan 2 07:23:54 PST 2023
Backl1ght created this revision.
Backl1ght added reviewers: HazardyKnusperkeks, MyDeveloperDay.
Backl1ght added a project: clang-format.
Herald added a project: All.
Backl1ght requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
This patch is to fix https://github.com/llvm/llvm-project/issues/59785.
related patches: https://reviews.llvm.org/D86581 and https://reviews.llvm.org/D100778.
I think the condition added in D100778 <https://reviews.llvm.org/D100778> is enough to judge shifts within conditions, the condition added in D86581 <https://reviews.llvm.org/D86581> is unnecessary and will cause template opener/closer parsed as binary operator, so I simply remove the condition added in D86581 <https://reviews.llvm.org/D86581>.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D140843
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
@@ -10341,6 +10341,8 @@
verifyFormat("bool_constant<a && noexcept(f())>");
verifyFormat("bool_constant<a || noexcept(f())>");
+ verifyFormat("if (std::tuple_size_v<T> > 0)");
+
// Not template parameters.
verifyFormat("return a < b && c > d;");
verifyFormat("void f() {\n"
Index: clang/lib/Format/TokenAnnotator.cpp
===================================================================
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -166,10 +166,9 @@
// parameter cases, but should not alter program semantics.
if (CurrentToken->Next && CurrentToken->Next->is(tok::greater) &&
Left->ParentBracket != tok::less &&
- (isKeywordWithCondition(*Line.First) ||
- CurrentToken->getStartOfNonWhitespace() ==
- CurrentToken->Next->getStartOfNonWhitespace().getLocWithOffset(
- -1))) {
+ CurrentToken->getStartOfNonWhitespace() ==
+ CurrentToken->Next->getStartOfNonWhitespace().getLocWithOffset(
+ -1)) {
return false;
}
Left->MatchingParen = CurrentToken;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D140843.485861.patch
Type: text/x-patch
Size: 1361 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230102/857651c5/attachment.bin>
More information about the cfe-commits
mailing list