Author: djasper Date: Mon Apr 24 09:28:49 2017 New Revision: 301182 URL: http://llvm.org/viewvc/llvm-project?rev=301182&view=rev Log: clang-format: Fix bad corner case in formatting of function types.
Before: std::function< LoooooooooooongTemplatedType<SomeType>*( LooooooooooooooooooooongType type)> function; After: std::function< LoooooooooooongTemplatedType< SomeType>*( LooooooooooooooooongType type)> function; clang-format generally avoids having lines like "SomeType>*(" as they lead to parameter lists that don't belong together to be aligned. However, in case it is better than the alternative, which can even be violating the column limit. Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp cfe/trunk/unittests/Format/FormatTest.cpp Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=301182&r1=301181&r2=301182&view=diff ============================================================================== --- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original) +++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Mon Apr 24 09:28:49 2017 @@ -792,7 +792,8 @@ unsigned ContinuationIndenter::moveState if (Previous && Previous->is(tok::question)) State.Stack.back().QuestionColumn = State.Column; } - if (!Current.opensScope() && !Current.closesScope()) + if (!Current.opensScope() && !Current.closesScope() && + !Current.is(TT_PointerOrReference)) State.LowestLevelOnLine = std::min(State.LowestLevelOnLine, Current.NestingLevel); if (Current.isMemberAccess()) Modified: cfe/trunk/unittests/Format/FormatTest.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=301182&r1=301181&r2=301182&view=diff ============================================================================== --- cfe/trunk/unittests/Format/FormatTest.cpp (original) +++ cfe/trunk/unittests/Format/FormatTest.cpp Mon Apr 24 09:28:49 2017 @@ -5221,6 +5221,12 @@ TEST_F(FormatTest, FormatsFunctionTypes) verifyFormat("void f() { function(*some_pointer_var)[0] = 10; }"); verifyFormat("int x = f(&h)();"); verifyFormat("returnsFunction(¶m1, ¶m2)(param);"); + verifyFormat("std::function<\n" + " LooooooooooongTemplatedType<\n" + " SomeType>*(\n" + " LooooooooooooooooongType type)>\n" + " function;", + getGoogleStyleWithColumns(40)); } TEST_F(FormatTest, FormatsPointersToArrayTypes) { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits