[PATCH] D91245: [clang-format] Recognize c++ coroutine keywords as unary operator to avoid misleading pointer alignment
Chuanqi Xu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Dec 14 21:53:56 PST 2020
ChuanqiXu updated this revision to Diff 311789.
ChuanqiXu added a comment.
add `verifyFormat("return *a", PASLeftStyle);` to clarify the change
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D91245/new/
https://reviews.llvm.org/D91245
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
@@ -7755,6 +7755,16 @@
verifyFormat("co_yield -1;");
verifyFormat("co_return -1;");
+
+ // The default setting for PointerAlignment is PAS_Right.
+ // But if we set PointerAlignment as PAS_Left, the formatter
+ // would mis-format the pointer alignment.
+ FormatStyle PASLeftStyle = getLLVMStyle();
+ PASLeftStyle.PointerAlignment = FormatStyle::PAS_Left;
+ verifyFormat("co_return *a;", PASLeftStyle);
+ verifyFormat("co_await *a;", PASLeftStyle);
+ verifyFormat("co_yield *a", PASLeftStyle);
+ verifyFormat("return *a;", PASLeftStyle);
}
TEST_F(FormatTest, DoesNotIndentRelativeToUnaryOperators) {
Index: clang/lib/Format/TokenAnnotator.cpp
===================================================================
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -1960,6 +1960,7 @@
if (PrevToken->isOneOf(tok::l_paren, tok::l_square, tok::l_brace,
tok::comma, tok::semi, tok::kw_return, tok::colon,
+ tok::kw_co_return, tok::kw_co_await, tok::kw_co_yield,
tok::equal, tok::kw_delete, tok::kw_sizeof,
tok::kw_throw) ||
PrevToken->isOneOf(TT_BinaryOperator, TT_ConditionalExpr,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D91245.311789.patch
Type: text/x-patch
Size: 1451 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201215/b44045b2/attachment.bin>
More information about the cfe-commits
mailing list