Fix incorrect cast identification.
Before: int a = sizeof(int *)+ b;"
After: int a = sizeof(int *) + b;
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@176957 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp
index 67ad86b..db5924c 100644
--- a/lib/Format/TokenAnnotator.cpp
+++ b/lib/Format/TokenAnnotator.cpp
@@ -621,7 +621,11 @@
bool ParensCouldEndDecl =
!Current.Children.empty() &&
Current.Children[0].isOneOf(tok::equal, tok::semi, tok::l_brace);
- if (ParensNotExpr && !ParensCouldEndDecl &&
+ bool IsSizeOfOrAlignOf =
+ Current.MatchingParen && Current.MatchingParen->Parent &&
+ Current.MatchingParen->Parent->isOneOf(tok::kw_sizeof,
+ tok::kw_alignof);
+ if (ParensNotExpr && !ParensCouldEndDecl && !IsSizeOfOrAlignOf &&
Contexts.back().IsExpression)
// FIXME: We need to get smarter and understand more cases of casts.
Current.Type = TT_CastRParen;
@@ -894,7 +898,7 @@
if (Right.isOneOf(tok::arrow, tok::period)) {
if (Line.Type == LT_BuilderTypeCall)
- return 14;
+ return prec::PointerToMember;
if (Left.isOneOf(tok::r_paren, tok::r_square) && Left.MatchingParen &&
Left.MatchingParen->ParameterCount > 0)
return 20; // Should be smaller than breaking at a nested comma.
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp
index 17aeaca..4e54212 100644
--- a/unittests/Format/FormatTest.cpp
+++ b/unittests/Format/FormatTest.cpp
@@ -2044,6 +2044,8 @@
verifyFormat("virtual void foo(int *) override;");
verifyFormat("virtual void foo(char &) const;");
verifyFormat("virtual void foo(int *a, char *) const;");
+ verifyFormat("int a = sizeof(int *) + b;");
+ verifyFormat("int a = alignof(int *) + b;");
}
TEST_F(FormatTest, FormatsFunctionTypes) {