From: Daniel Jasper Date: Mon, 12 Aug 2013 12:16:34 +0000 (+0000) Subject: clang-format: Correctly format alias declarations. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=53352600b7370b1d33b9fde1adda207fd9d7dcd1;p=clang clang-format: Correctly format alias declarations. Before: template using MyCallback = void(CallbackClass::*)(SomeObject * Data);"); After: template using MyCallback = void (CallbackClass::*)(SomeObject *Data);"); Also fix three wrong indentations. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@188172 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp index 255f5142f0..322e867006 100644 --- a/lib/Format/Format.cpp +++ b/lib/Format/Format.cpp @@ -973,7 +973,7 @@ private: // Exempts unterminated string literals from line breaking. The user will // likely want to terminate the string before any line breaking is done. if (Current.IsUnterminatedLiteral) - return 0; + return 0; Token.reset(new BreakableStringLiteral(Current, StartColumn, Line.InPPDirective, Encoding)); @@ -1228,7 +1228,7 @@ private: return true; if (!Style.Cpp11BracedListStyle && Current.is(tok::r_brace) && State.Stack.back().BreakBeforeClosingBrace) - return true; + return true; if (Previous.is(tok::semi) && State.LineContainsContinuedForLoopSection) return true; if (Style.BreakConstructorInitializersBeforeComma) { diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 1a9012fa88..56a1dbac76 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -123,6 +123,10 @@ private: } } + if (CurrentToken->Previous->Type == TT_PointerOrReference && + CurrentToken->Previous->Previous->isOneOf(tok::l_paren, + tok::coloncolon)) + MightBeFunctionType = true; if (CurrentToken->is(tok::r_paren)) { if (MightBeFunctionType && CurrentToken->Next && (CurrentToken->Next->is(tok::l_paren) || @@ -152,10 +156,6 @@ private: } if (CurrentToken->isOneOf(tok::r_square, tok::r_brace)) return false; - if (CurrentToken->Previous->Type == TT_PointerOrReference && - CurrentToken->Previous->Previous->isOneOf(tok::l_paren, - tok::coloncolon)) - MightBeFunctionType = true; updateParameterCount(Left, CurrentToken); if (CurrentToken->is(tok::comma) && CurrentToken->Next && !CurrentToken->Next->HasUnescapedNewline && @@ -577,6 +577,7 @@ private: void determineTokenType(FormatToken &Current) { if (Current.getPrecedence() == prec::Assignment && + !Line.First->isOneOf(tok::kw_template, tok::kw_using) && (!Current.Previous || Current.Previous->isNot(tok::kw_operator))) { Contexts.back().IsExpression = true; for (FormatToken *Previous = Current.Previous; @@ -593,7 +594,7 @@ private: (Current.is(tok::l_paren) && !Line.MustBeDeclaration && !Line.InPPDirective && (!Current.Previous || - !Current.Previous->isOneOf(tok::kw_for, tok::kw_catch)))) { + !Current.Previous->isOneOf(tok::kw_for, tok::kw_catch)))) { Contexts.back().IsExpression = true; } else if (Current.isOneOf(tok::r_paren, tok::greater, tok::comma)) { for (FormatToken *Previous = Current.Previous; diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 739c0e5ad9..f5e16d0e89 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -3797,9 +3797,14 @@ TEST_F(FormatTest, FormatsFunctionTypes) { verifyFormat("void *(*a)(int *, SomeType *);"); verifyFormat("int (*func)(void *);"); verifyFormat("void f() { int (*func)(void *); }"); + verifyFormat("template \n" + "using MyCallback = void (CallbackClass::*)(SomeObject *Data);"); verifyGoogleFormat("A;"); verifyGoogleFormat("void* (*a)(int);"); + verifyGoogleFormat( + "template \n" + "using MyCallback = void (CallbackClass::*)(SomeObject* Data);"); // Other constructs can look somewhat like function types: verifyFormat("A a;");