[PATCH] D134049: [clang-format] Disallow trailing return arrows to be operators
Emilia Dreamer via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 16 09:57:45 PDT 2022
rymiel updated this revision to Diff 460810.
rymiel added a comment.
Also test the annotated value of the arrow
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D134049/new/
https://reviews.llvm.org/D134049
Files:
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/TokenAnnotatorTest.cpp
Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===================================================================
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -440,6 +440,14 @@
ASSERT_EQ(Tokens.size(), 18u) << Tokens;
EXPECT_TOKEN(Tokens[11], tok::kw_requires, TT_RequiresClause);
+ Tokens = annotate("template <typename T>\n"
+ "requires Bar<T> || Baz<T>\n"
+ "auto foo(T) -> int;");
+ ASSERT_EQ(Tokens.size(), 24u) << Tokens;
+ EXPECT_EQ(Tokens[11]->FakeLParens.size(), 0u);
+ EXPECT_TOKEN(Tokens[5], tok::kw_requires, TT_RequiresClause);
+ EXPECT_TOKEN(Tokens[20], tok::arrow, TT_TrailingReturnArrow);
+
Tokens = annotate("template <typename T>\n"
"struct S {\n"
" void foo() const requires Bar<T>;\n"
Index: clang/lib/Format/TokenAnnotator.cpp
===================================================================
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -2611,8 +2611,10 @@
}
if (Current->is(TT_BinaryOperator) || Current->is(tok::comma))
return Current->getPrecedence();
- if (Current->isOneOf(tok::period, tok::arrow))
+ if (Current->isOneOf(tok::period, tok::arrow) &&
+ !Current->is(TT_TrailingReturnArrow)) {
return PrecedenceArrowAndPeriod;
+ }
if ((Style.Language == FormatStyle::LK_Java || Style.isJavaScript()) &&
Current->isOneOf(Keywords.kw_extends, Keywords.kw_implements,
Keywords.kw_throws)) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D134049.460810.patch
Type: text/x-patch
Size: 1617 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220916/4acb6e30/attachment.bin>
More information about the cfe-commits
mailing list