From ff0912e6325fc389b33c0e637fd10ad611fa3fbc Mon Sep 17 00:00:00 2001 From: Marco Stornelli Date: Sun, 31 May 2020 09:46:41 +0200 Subject: [PATCH] Bug 487990 - Fix format of variadic functions Change-Id: I802d032f733247178db46c8fe43fdb9350555509 --- .../cdt/internal/formatter/CodeFormatterVisitor.java | 4 +++- .../eclipse/cdt/ui/tests/text/CodeFormatterTest.java | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) 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 19239262c98..240db77686c 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 @@ -2582,7 +2582,9 @@ private void formatList(List elements, ListOptions options, boolean encloseIn } if (addEllipsis) { if (i > 0) { - scribe.printNextToken(options.fSeparatorToken, options.fSpaceBeforeSeparator); + if (peekNextToken() == options.fSeparatorToken) { + scribe.printNextToken(options.fSeparatorToken, options.fSpaceBeforeSeparator); + } scribe.printTrailingComment(); } scribe.alignFragment(alignment, i); 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 47269ee5a89..47ee70ce118 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 @@ -4777,4 +4777,15 @@ public void testLambdaExpressionOnlyDefCapture_Bug561559() throws Exception { public void testNoexcept_Bug562723() throws Exception { assertFormatterResult(); } + + //void foo(int...) {} + //int main() {} + + //void foo(int ...) { + //} + //int main() { + //} + public void testVariadicFunction_Bug487990() throws Exception { + assertFormatterResult(); + } }