r216540 - clang-format: Fix regression in formatting of braced initializers.
Daniel Jasper
djasper at google.com
Wed Aug 27 04:53:27 PDT 2014
Author: djasper
Date: Wed Aug 27 06:53:26 2014
New Revision: 216540
URL: http://llvm.org/viewvc/llvm-project?rev=216540&view=rev
Log:
clang-format: Fix regression in formatting of braced initializers.
Before:
Node n{1, Node{1000}, //
2};
After:
Node n{1, Node{1000}, //
2};
Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=216540&r1=216539&r2=216540&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Wed Aug 27 06:53:26 2014
@@ -313,7 +313,9 @@ private:
updateParameterCount(Left, CurrentToken);
if (CurrentToken->isOneOf(tok::colon, tok::l_brace)) {
FormatToken *Previous = CurrentToken->getPreviousNonComment();
- if (Previous->is(tok::identifier))
+ if ((CurrentToken->is(tok::colon) ||
+ Style.Language == FormatStyle::LK_Proto) &&
+ Previous->is(tok::identifier))
Previous->Type = TT_SelectorName;
if (CurrentToken->is(tok::colon))
Left->Type = TT_DictLiteral;
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=216540&r1=216539&r2=216540&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Wed Aug 27 06:53:26 2014
@@ -5466,6 +5466,8 @@ TEST_F(FormatTest, LayoutCxx11BraceIniti
verifyFormat("int foo(int i) { return fo1{}(i); }");
verifyFormat("auto i = decltype(x){};");
verifyFormat("std::vector<int> v = {1, 0 /* comment */};");
+ verifyFormat("Node n{1, Node{1000}, //\n"
+ " 2};");
// In combination with BinPackParameters = false.
FormatStyle NoBinPacking = getLLVMStyle();
More information about the cfe-commits
mailing list