1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-22 06:02:11 +02:00

Bug 561559 - Fix formatting def capture lambda expressions

We missed a space before the closing brackets if the proper option
was selected.

Change-Id: Ibbb09c3c961dc1b5e22aaa65ffb5d9878c2bb08b
This commit is contained in:
Marco Stornelli 2020-03-29 16:23:48 +02:00
parent 1cb1cdaa9a
commit 4a4c5fca4d
2 changed files with 22 additions and 2 deletions

View file

@ -2515,8 +2515,9 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
final int elementsLength = elements.size(); final int elementsLength = elements.size();
if (encloseInParen) { if (encloseInParen) {
boolean spaceBeforeClosingParen = elements.isEmpty() && !addEllipsis ? options.fSpaceBetweenEmptyParen boolean spaceBeforeClosingParen = elements.isEmpty() && !addEllipsis
: options.fSpaceBeforeClosingParen; && options.captureDefault == CaptureDefault.UNSPECIFIED ? options.fSpaceBetweenEmptyParen
: options.fSpaceBeforeClosingParen;
tailFormatter = new ClosingParensesisTailFormatter(spaceBeforeClosingParen, tailFormatter, tailFormatter = new ClosingParensesisTailFormatter(spaceBeforeClosingParen, tailFormatter,
options.rightToken); options.rightToken);
} }

View file

@ -4771,4 +4771,23 @@ public class CodeFormatterTest extends BaseUITestCase {
public void testDeductionGuideExplicit() throws Exception { public void testDeductionGuideExplicit() throws Exception {
assertFormatterResult(); assertFormatterResult();
} }
//int main() {
// auto f = [&](){
// };
// return 0;
//}
//int main() {
// auto f = [ & ]() {
// };
// return 0;
//}
public void testLambdaExpressionOnlyDefCapture_Bug561559() throws Exception {
fOptions.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_OPENING_PAREN_IN_METHOD_DECLARATION,
CCorePlugin.INSERT);
fOptions.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_CLOSING_PAREN_IN_METHOD_DECLARATION,
CCorePlugin.INSERT);
assertFormatterResult();
}
} }