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 24e8ede06e6..f2d13581889 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 @@ -3593,9 +3593,13 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, stmt.accept(this); scribe.unIndent(); } else { - scribe.printTrailingComment(); - scribe.startNewLine(); - scribe.indent(); + // Don't insert a line break if we have already passed the start of the statement. + // This is possible with macro expansions. + if (scribe.scanner.getCurrentPosition() <= stmt.getFileLocation().getNodeOffset()) { + scribe.printTrailingComment(); + scribe.startNewLine(); + scribe.indent(); + } stmt.accept(this); scribe.unIndent(); } 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 65fda22bb23..e93f5ca173a 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 @@ -1435,6 +1435,24 @@ public class CodeFormatterTest extends BaseUITestCase { assertFormatterResult(); } + //#define MACRO(a, b) while (a) b + //bool f(); + //void g(); + //void test() { + //MACRO(f(), g()); + //} + + //#define MACRO(a, b) while (a) b + //bool f(); + //void g(); + //void test() { + // MACRO(f(), g()); + //} + public void testMacroStatement() throws Exception { + fOptions.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, CCorePlugin.SPACE); + assertFormatterResult(); + } + //bool member __attribute__ ((__unused__)) = false; //bool member __attribute__ ((__unused__)) = false;