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 2e89d0d1055..2471bcbab6e 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 @@ -3090,6 +3090,10 @@ public class CodeFormatterVisitor extends CPPASTVisitor { } if (!endsWithMacroExpansion) { formatClosingBrace(block_brace_position); + } else { + if (DefaultCodeFormatterConstants.NEXT_LINE_SHIFTED.equals(block_brace_position)) { + 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 04e50ff1985..d15947cf68f 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 @@ -948,6 +948,58 @@ public class CodeFormatterTest extends BaseUITestCase { assertFormatterResult(); } + //#define BLOCK { } + //#define DOIT1() { } + //#define DOIT2() do { } while(false) + //#define ALWAYS if(true) + //#define NEVER if(false) + //#define FOREVER for(;;) + // + //void foo() { + // int i=0; + // if (true) DOIT1(); + // if (true) DOIT2(); + // for (;;) BLOCK + // ALWAYS BLOCK + // NEVER FOREVER BLOCK + // switch(i) { + // case 0: BLOCK + // } + //} + + //#define BLOCK { } + //#define DOIT1() { } + //#define DOIT2() do { } while(false) + //#define ALWAYS if(true) + //#define NEVER if(false) + //#define FOREVER for(;;) + // + //void + //foo() + //{ + // int i = 0; + // if (true) + // DOIT1(); + // if (true) + // DOIT2(); + // for (;;) + // BLOCK + // ALWAYS + // BLOCK + // NEVER + // FOREVER + // BLOCK + // switch (i) + // { + // case 0: + // BLOCK + // } + //} + public void testCompoundStatementAsMacroGNU_Bug244928() throws Exception { + fOptions= DefaultCodeFormatterOptions.getGNUSettings().getMap(); + assertFormatterResult(); + } + //#define A (0) //#define B (1) //#define ARGS (A, B)