The function type declared in an std::function template parameter is confused for a cast:
Currently:
Pass: "std::function< void(int, int) > fct;", Spaces);
Fail: "void inFunction() { std::function< void(int, int) > fct; }",
Actual result "void inFunction() { std::function< void(int, int)> fct; }" (no space between ")>")
Root cause:
-Inside a function definition, Line.MustBeDeclaration is not true.
-This allows the context IsExpression to be true.
"Contexts.back().IsExpression = !ParametersOfFunctionType && !IsForOrCatch;"
-which then allow the right parenthesis to be marked incorrectly as cast, and the left there after.
"if (ParensAreType && !ParensCouldEndDecl && !IsSizeOfOrAlignOf &&
(Contexts.size() > 1 && Contexts[Contexts.size() - 2].IsExpression)) IsCast = true;"
Because at the time of this marking, the angle bracket is not yet established as a template opener and closer, this fix address the issue by resetting the type to unknown for the parenthesis.(Unknown is the type the parenthesis hold in the case the line must be a declaration).
It seems there should be a better alternative, but I am not sure where I should look.
The tests are updated in 2 places as this incorrect deduction result in incorrect spacing before the angle bracket, but also inside the parenthesis if space is required there but not in cast.
Run all the test in FormatTests project and spot checked clang format output for TokenAnnotator.cpp and FormatTest.cpp is the same before and after the patch.