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 43b7ed48ba1..824fd2cd283 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 @@ -1886,8 +1886,15 @@ public class CodeFormatterVisitor extends CPPASTVisitor { scribe.space(); } node.getTypeId().accept(this); - scribe.printNextToken(Token.tRPAREN, preferences.insert_space_before_closing_paren_in_cast); - if (preferences.insert_space_after_closing_paren_in_cast) { + try { + if (node.getTypeId().getTrailingSyntax().getType() == IToken.tRPAREN) { + scribe.printNextToken(Token.tRPAREN, preferences.insert_space_before_closing_paren_in_cast); + if (preferences.insert_space_after_closing_paren_in_cast) { + scribe.space(); + } + } + } catch (UnsupportedOperationException exc) { + } catch (ExpansionOverlapsBoundaryException exc) { scribe.space(); } // operand 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 a123209585b..867bbf608d3 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 @@ -1347,4 +1347,13 @@ public class CodeFormatterTest extends BaseUITestCase { public void testWideStringLiteral_Bug292626() throws Exception { assertFormatterResult(); } + + //#define INT (int) + //int i = INT 1; + + //#define INT (int) + //int i = INT 1; + public void testCastAsMacro_Bug285901() throws Exception { + assertFormatterResult(); + } }