From 7424d79613a67ba200b6801468f2b59cde7ab087 Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Tue, 14 May 2013 08:34:47 +0000 Subject: [PATCH] Don't format sizeof/alignof as function types. Before: A a; After: A a; git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@181764 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/TokenAnnotator.cpp | 4 +++- unittests/Format/FormatTest.cpp | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 29eaaa8b58..0f91b11033 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -173,7 +173,9 @@ private: } if (CurrentToken->isOneOf(tok::r_square, tok::r_brace)) return false; - if (CurrentToken->Parent->Type == TT_PointerOrReference && + if (Left->Parent && + !Left->Parent->isOneOf(tok::kw_sizeof, tok::kw_alignof) && + CurrentToken->Parent->Type == TT_PointerOrReference && CurrentToken->Parent->Parent->isOneOf(tok::l_paren, tok::coloncolon)) Left->DefinesFunctionType = true; updateParameterCount(Left, CurrentToken); diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index b2ae3d2560..b2393f578b 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -2790,6 +2790,10 @@ TEST_F(FormatTest, FormatsFunctionTypes) { verifyGoogleFormat("A;"); verifyGoogleFormat("void* (*a)(int);"); + + // Other constructs can look like function types: + verifyFormat("A a;"); + verifyFormat("A a;"); } TEST_F(FormatTest, BreaksLongDeclarations) {