aboutsummaryrefslogtreecommitdiff
path: root/clang/unittests
diff options
context:
space:
mode:
authorKrasimir Georgiev <krasimir@google.com>2022-07-15 11:36:08 +0200
committerKrasimir Georgiev <krasimir@google.com>2022-07-15 11:45:12 +0200
commit8dd2ef2130852e406dab6097b1feb248bf16ce91 (patch)
tree300d4b5b23ee32df916bdb38acca42e2a3f8350d /clang/unittests
parent8a519b3c214547dbd7b6a027d83ee5f79b5f09c0 (diff)
downloadllvm-8dd2ef2130852e406dab6097b1feb248bf16ce91.zip
llvm-8dd2ef2130852e406dab6097b1feb248bf16ce91.tar.gz
llvm-8dd2ef2130852e406dab6097b1feb248bf16ce91.tar.bz2
[clang-format] distinguish multiplication after brace-init from pointer
After https://github.com/llvm/llvm-project/commit/b646f0955574c6ad4c156c9db522e46f597cfda9, the added regression test started being formatted as-if the multiplication `*` was a pointer. This adapts the heuristic to distinguish between these two cases. Reviewed By: jackhong12, curdeius, HazardyKnusperkeks, owenpan Differential Revision: https://reviews.llvm.org/D129771
Diffstat (limited to 'clang/unittests')
-rw-r--r--clang/unittests/Format/FormatTest.cpp3
-rw-r--r--clang/unittests/Format/TokenAnnotatorTest.cpp3
2 files changed, 6 insertions, 0 deletions
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index ba07584..08cfdbe 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -10458,6 +10458,9 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {
verifyFormat("class {\n"
"}* ptr;",
Style);
+ // Don't confuse a multiplication after a brace-initialized expression with
+ // a class pointer.
+ verifyFormat("int i = int{42} * 34;", Style);
verifyFormat("struct {\n"
"}&& ptr = {};",
Style);
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp
index df1b052..a2474d5c 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -111,6 +111,9 @@ TEST_F(TokenAnnotatorTest, UnderstandsUsesOfStarAndAmp) {
"} &&ptr = {};");
EXPECT_EQ(Tokens.size(), 10u) << Tokens;
EXPECT_TOKEN(Tokens[3], tok::ampamp, TT_PointerOrReference);
+ Tokens = annotate("int i = int{42} * 2;");
+ EXPECT_EQ(Tokens.size(), 11u) << Tokens;
+ EXPECT_TOKEN(Tokens[7], tok::star, TT_BinaryOperator);
}
TEST_F(TokenAnnotatorTest, UnderstandsUsesOfPlusAndMinus) {