diff options
-rw-r--r-- | lib/Format/TokenAnnotator.cpp | 8 | ||||
-rw-r--r-- | unittests/Format/FormatTest.cpp | 2 |
2 files changed, 8 insertions, 2 deletions
diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 67ad86b624..db5924c8a5 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -621,7 +621,11 @@ private: 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 @@ unsigned TokenAnnotator::splitPenalty(const AnnotatedLine &Line, 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 17aeacae5c..4e54212f99 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -2044,6 +2044,8 @@ TEST_F(FormatTest, FormatsCasts) { 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) { |