diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java index 70fbedd4890..08f8b002805 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java @@ -2515,8 +2515,9 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, final int elementsLength = elements.size(); if (encloseInParen) { - boolean spaceBeforeClosingParen = elements.isEmpty() && !addEllipsis ? options.fSpaceBetweenEmptyParen - : options.fSpaceBeforeClosingParen; + boolean spaceBeforeClosingParen = elements.isEmpty() && !addEllipsis + && options.captureDefault == CaptureDefault.UNSPECIFIED ? options.fSpaceBetweenEmptyParen + : options.fSpaceBeforeClosingParen; tailFormatter = new ClosingParensesisTailFormatter(spaceBeforeClosingParen, tailFormatter, options.rightToken); } diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java index 74997c84ac7..c72f0b79fa0 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java @@ -4771,4 +4771,23 @@ public class CodeFormatterTest extends BaseUITestCase { public void testDeductionGuideExplicit() throws Exception { 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(); + } }