[PATCH] D93626: [clang-format] PR48535 clang-format Incorrectly Removes Space After C Style Cast When Type Is Not a Pointer
MyDeveloperDay via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Dec 23 06:45:48 PST 2020
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5426b2f9ed9f: [clang-format] PR48535 clang-format Incorrectly Removes Space After C Style… (authored by MyDeveloperDay).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D93626/new/
https://reviews.llvm.org/D93626
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
@@ -11989,6 +11989,20 @@
" do_something((int) i);\n"
"} while (something( ));",
Spaces);
+
+ verifyFormat("size_t idx = (size_t) (ptr - ((char *) file));", Spaces);
+ verifyFormat("size_t idx = (size_t) a;", Spaces);
+ verifyFormat("size_t idx = (size_t) (a - 1);", Spaces);
+ verifyFormat("size_t idx = (a->*foo)(a - 1);", Spaces);
+ verifyFormat("size_t idx = (a->foo)(a - 1);", Spaces);
+ verifyFormat("size_t idx = (*foo)(a - 1);", Spaces);
+ Spaces.SpaceAfterCStyleCast = false;
+ verifyFormat("size_t idx = (size_t)(ptr - ((char *)file));", Spaces);
+ verifyFormat("size_t idx = (size_t)a;", Spaces);
+ verifyFormat("size_t idx = (size_t)(a - 1);", Spaces);
+ verifyFormat("size_t idx = (a->*foo)(a - 1);", Spaces);
+ verifyFormat("size_t idx = (a->foo)(a - 1);", Spaces);
+ verifyFormat("size_t idx = (*foo)(a - 1);", Spaces);
}
TEST_F(FormatTest, ConfigurableSpacesInSquareBrackets) {
Index: clang/lib/Format/TokenAnnotator.cpp
===================================================================
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -1915,6 +1915,13 @@
if (Tok.Next->isOneOf(tok::identifier, tok::kw_this))
return true;
+ if (Tok.Next->is(tok::l_paren) &&
+ !(Tok.Previous && Tok.Previous->is(tok::identifier) &&
+ Tok.Previous->Previous &&
+ Tok.Previous->Previous->isOneOf(tok::arrowstar, tok::arrow,
+ tok::star)))
+ return true;
+
if (!Tok.Next->Next)
return false;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D93626.313544.patch
Type: text/x-patch
Size: 1789 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201223/8588687b/attachment-0001.bin>
More information about the cfe-commits
mailing list