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 89815c3e5e4..6fcac39eb33 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 @@ -2504,13 +2504,19 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, } private int visit(IASTCastExpression node) { + Runnable tailFormatter = null; switch (node.getOperator()) { case IASTCastExpression.op_cast: scribe.printNextToken(Token.tLPAREN, false); if (preferences.insert_space_after_opening_paren_in_cast) { scribe.space(); } - node.getTypeId().accept(this); + tailFormatter = scribe.takeTailFormatter(); + try { + node.getTypeId().accept(this); + } finally { + scribe.setTailFormatter(tailFormatter); + } try { if (node.getTypeId().getTrailingSyntax().getType() == IToken.tRPAREN) { scribe.printNextToken(Token.tRPAREN, preferences.insert_space_before_closing_paren_in_cast); @@ -2535,7 +2541,12 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, if (preferences.insert_space_after_opening_angle_bracket_in_template_arguments) { scribe.space(); } - node.getTypeId().accept(this); + tailFormatter = scribe.takeTailFormatter(); + try { + node.getTypeId().accept(this); + } finally { + scribe.setTailFormatter(tailFormatter); + } scribe.printNextToken(Token.tGT, preferences.insert_space_before_closing_angle_bracket_in_template_arguments); if (preferences.insert_space_before_opening_paren_in_method_invocation) { @@ -2546,7 +2557,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, if (preferences.insert_space_after_opening_paren_in_method_invocation) { scribe.space(); } - Runnable tailFormatter = scribe.takeTailFormatter(); + tailFormatter = scribe.takeTailFormatter(); try { node.getOperand().accept(this); } finally { 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 6e73fea3322..0bcab92ea21 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 @@ -4093,4 +4093,34 @@ public class CodeFormatterTest extends BaseUITestCase { public void testNestedNamespace_Bug546221() throws Exception { assertFormatterResult(); } + + //void someAction(int i) { + //} + //int foo() { + // auto f = static_cast(&someAction); + //} + + //void someAction(int i) { + //} + //int foo() { + // auto f = static_cast(&someAction); + //} + public void testCastFuncDeclarator1_Bug390324() throws Exception { + assertFormatterResult(); + } + + //void someAction(int i) { + //} + //int foo() { + // auto f = (void (*)(int)) (&someAction); + //} + + //void someAction(int i) { + //} + //int foo() { + // auto f = (void (*)(int)) (&someAction); + //} + public void testCastFuncDeclarator2_Bug390324() throws Exception { + assertFormatterResult(); + } }