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 f2d13581889..9a6a33ba7af 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 @@ -3595,13 +3595,16 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, } else { // Don't insert a line break if we have already passed the start of the statement. // This is possible with macro expansions. + boolean indented = false; if (scribe.scanner.getCurrentPosition() <= stmt.getFileLocation().getNodeOffset()) { scribe.printTrailingComment(); scribe.startNewLine(); scribe.indent(); + indented = true; } stmt.accept(this); - scribe.unIndent(); + if (indented) + 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 e93f5ca173a..5d54c2b9182 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 @@ -1440,6 +1440,7 @@ public class CodeFormatterTest extends BaseUITestCase { //void g(); //void test() { //MACRO(f(), g()); + //int i = 0; //} //#define MACRO(a, b) while (a) b @@ -1447,6 +1448,7 @@ public class CodeFormatterTest extends BaseUITestCase { //void g(); //void test() { // MACRO(f(), g()); + // int i = 0; //} public void testMacroStatement() throws Exception { fOptions.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, CCorePlugin.SPACE);