[PATCH] D69573: [clang-format] [PR36294] AlwaysBreakAfterReturnType works incorrectly for some operator functions
MyDeveloperDay via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 29 13:50:11 PDT 2019
MyDeveloperDay updated this revision to Diff 226961.
MyDeveloperDay added a comment.
Trying to address review comments
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D69573/new/
https://reviews.llvm.org/D69573
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
@@ -6111,7 +6111,13 @@
"void\n"
"A::operator>>() {}\n"
"void\n"
- "A::operator+() {}\n",
+ "A::operator+() {}\n"
+ "void\n"
+ "A::operator*() {}\n"
+ "void\n"
+ "A::operator->() {}\n"
+ "void\n"
+ "A::operator!() {}\n",
Style);
verifyFormat("void *operator new(std::size_t s);", // No break here.
Style);
Index: clang/lib/Format/TokenAnnotator.cpp
===================================================================
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -952,7 +952,7 @@
consumeToken();
if (CurrentToken &&
CurrentToken->Previous->isOneOf(TT_BinaryOperator, TT_UnaryOperator,
- tok::comma))
+ tok::comma, tok::arrow))
CurrentToken->Previous->Type = TT_OverloadedOperator;
}
if (CurrentToken) {
@@ -1344,8 +1344,12 @@
Contexts.back().IsExpression = false;
} else if (Current.is(tok::kw_new)) {
Contexts.back().CanBeExpression = false;
- } else if (Current.isOneOf(tok::semi, tok::exclaim)) {
+ } else if (Current.is(tok::semi) ||
+ (Current.is(tok::exclaim) && Current.Previous &&
+ !Current.Previous->is(tok::kw_operator))) {
// This should be the condition or increment in a for-loop.
+ // But not operator !() (can't use TT_OverloadedOperator here as its not
+ // been annotated yet).
Contexts.back().IsExpression = true;
}
}
@@ -2085,6 +2089,8 @@
return Next;
if (Next->is(TT_OverloadedOperator))
continue;
+ if (Next->is(TT_PointerOrReference))
+ continue;
if (Next->isOneOf(tok::kw_new, tok::kw_delete)) {
// For 'new[]' and 'delete[]'.
if (Next->Next && Next->Next->is(tok::l_square) && Next->Next->Next &&
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D69573.226961.patch
Type: text/x-patch
Size: 2242 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191029/6ea81782/attachment-0001.bin>
More information about the cfe-commits
mailing list