[PATCH] D132911: [clang-format] Fix annotating when deleting array of pointers
Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 2 14:57:09 PDT 2022
This revision was automatically updated to reflect the committed changes.
Closed by commit rG3bbdf06b2827: [clang-format] Fix annotating when deleting array of pointers (authored by jackh <jackhuang1205 at gmail.com>).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D132911/new/
https://reviews.llvm.org/D132911
Files:
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTest.cpp
clang/unittests/Format/TokenAnnotatorTest.cpp
Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===================================================================
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -120,6 +120,17 @@
Tokens = annotate("int i = int{42} * 2;");
EXPECT_EQ(Tokens.size(), 11u) << Tokens;
EXPECT_TOKEN(Tokens[7], tok::star, TT_BinaryOperator);
+
+ Tokens = annotate("delete[] *ptr;");
+ EXPECT_EQ(Tokens.size(), 7u) << Tokens;
+ EXPECT_TOKEN(Tokens[3], tok::star, TT_UnaryOperator);
+ Tokens = annotate("delete[] **ptr;");
+ EXPECT_EQ(Tokens.size(), 8u) << Tokens;
+ EXPECT_TOKEN(Tokens[3], tok::star, TT_UnaryOperator);
+ EXPECT_TOKEN(Tokens[4], tok::star, TT_UnaryOperator);
+ Tokens = annotate("delete[] *(ptr);");
+ EXPECT_EQ(Tokens.size(), 9u) << Tokens;
+ EXPECT_TOKEN(Tokens[3], tok::star, TT_UnaryOperator);
}
TEST_F(TokenAnnotatorTest, UnderstandsUsesOfPlusAndMinus) {
Index: clang/unittests/Format/FormatTest.cpp
===================================================================
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -10535,6 +10535,11 @@
"} &&ptr = {};",
Style);
+ Style.PointerAlignment = FormatStyle::PAS_Left;
+ verifyFormat("delete[] *ptr;", Style);
+ verifyFormat("delete[] **ptr;", Style);
+ verifyFormat("delete[] *(ptr);", Style);
+
verifyIndependentOfContext("MACRO(int *i);");
verifyIndependentOfContext("MACRO(auto *a);");
verifyIndependentOfContext("MACRO(const A *a);");
Index: clang/lib/Format/TokenAnnotator.cpp
===================================================================
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -2372,6 +2372,9 @@
!PrevToken->MatchingParen)
return TT_PointerOrReference;
+ if (PrevToken->endsSequence(tok::r_square, tok::l_square, tok::kw_delete))
+ return TT_UnaryOperator;
+
if (PrevToken->Tok.isLiteral() ||
PrevToken->isOneOf(tok::r_paren, tok::r_square, tok::kw_true,
tok::kw_false, tok::r_brace)) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D132911.457711.patch
Type: text/x-patch
Size: 2125 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220902/83818c10/attachment-0001.bin>
More information about the cfe-commits
mailing list