[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
Tue Dec 15 02:45:29 PST 2020
ChuanqiXu updated this revision to Diff 311849.
ChuanqiXu added a comment.
Edit the comment to avoid misleading.
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,15 @@
verifyFormat("co_yield -1;");
verifyFormat("co_return -1;");
+
+ // Check that * is not treated as a binary operator when we set PointerAlignment
+ // as PAS_Left after a keyword and not a declaration.
+ 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.311849.patch
Type: text/x-patch
Size: 1421 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201215/d016271d/attachment-0001.bin>
More information about the cfe-commits
mailing list