[PATCH] Fix spacing for function with ref-qualification when using SpacesInCStyleCastParentheses != SpacesInParentheses
j.dufraigne at gmail.com
Sat Feb 21 18:15:24 PST 2015
If the approach is not right, I'll try to rework the fix with your feedback.
FormatStyle Spaces = getLLVMStyle();
verifyFormat("Deleted &operator=(const Deleted &)& = default;");
verifyFormat("Deleted( const Deleted & )& = default;", Spaces); // Fail "Deleted(const Deleted &)& = default;"
Spaces.SpacesInCStyleCastParentheses = true;
verifyFormat("Deleted(const Deleted &)& = default;", Spaces); // Fail "Deleted( const Deleted & )& = default;"
The cast seemed too eager: There does not seem to be a reason for a binary operator to follow a C-cast.
The type of the function reference qualification seems to make sense as TT_PointerOrReference:
-Extend in the case of to handle the '&&' case "Deleted(const Deleted &)&& = default;"
-Extend to handle the case without '=' for '*', '&' and '&&' case "Deleted(const Deleted &)&;"
Ensure no spaces between parenthesis and the reference qualification:
"Deleted &operator=(const Deleted &)&;" can be detected with TT_OverloadedOperatorLParen
"SomeType MemberFunction(const Deleted &)&;" can be detected with TT_FunctionDeclarationName
But "Deleted(const Deleted &)&;" cannot be detected with existing mechanisms:
- Introduce TT_FunctionLParen to recognize Function parentheses.
TT_FunctionLParen assume that an 'identifier(' necessarily represent a function declaration or function call including constructors.
It could also happen for functional C-cast, but it seem safe to assume they should be treated as function.
This changeset is already quite big for me, so I did not try to ensure TT_FunctionDeclarationName is always followed by TT_FunctionLParen.
As TT_FunctionDeclarationName, TT_FunctionLParen is currently a best effort guess. It could be added in a separate changeset with a new set of tests.
The set of unit tests is not quite minimal, it needs:
- To cover LLVM, Google, SpacesInCStyleCastParentheses, SpacesInParentheses.
- Both ref-qualifications : '&' and '&&'
- Operator, function, and constructor.
Verify clang-format output is unchanged for the 3 modified files FormatToken.h, TokenAnnotator.cpp, FormatTest.cpp
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 6122 bytes
Desc: not available
More information about the cfe-commits