[PATCH] Fix spacing for function with ref-qualification when using SpacesInCStyleCastParentheses != SpacesInParentheses
Jean-Philippe Dufraigne
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.
Problem:
========
FormatStyle Spaces = getLLVMStyle();
verifyFormat("Deleted &operator=(const Deleted &)& = default;");
Spaces.SpacesInParentheses= true;
verifyFormat("Deleted( const Deleted & )& = default;", Spaces); // Fail "Deleted(const Deleted &)& = default;"
Spaces.SpacesInCStyleCastParentheses = true;
Spaces.SpacesInParentheses= false;
verifyFormat("Deleted(const Deleted &)& = default;", Spaces); // Fail "Deleted( const Deleted & )& = default;"
Solution:
=======
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.
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.
Additional test:
Verify clang-format output is unchanged for the 3 modified files FormatToken.h, TokenAnnotator.cpp, FormatTest.cpp
http://reviews.llvm.org/D7813
Files:
lib/Format/FormatToken.h
lib/Format/TokenAnnotator.cpp
unittests/Format/FormatTest.cpp
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D7813.20467.patch
Type: text/x-patch
Size: 6122 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150222/8b7db63c/attachment.bin>
More information about the cfe-commits
mailing list