Skip to main content
summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorMarco Stornelli2019-04-14 09:23:43 -0400
committerMarco Stornelli2019-05-08 13:30:49 -0400
commit5b869afec3affa8714258aad09a1ec5d8f14312a (patch)
treea756b45753266eebb7a79e608132f30a1ff54bbc /core
parentdb0cc1f9a46f32a821347b49edccc7e560da8ee5 (diff)
downloadorg.eclipse.cdt-5b869afec3affa8714258aad09a1ec5d8f14312a.tar.gz
org.eclipse.cdt-5b869afec3affa8714258aad09a1ec5d8f14312a.tar.xz
org.eclipse.cdt-5b869afec3affa8714258aad09a1ec5d8f14312a.zip
Bug 390324 - Fix cast operator containing func declarator
Change-Id: I935fe1daabd18372062916e5a896896f5cab604f Signed-off-by: Marco Stornelli <marco.stornelli@gmail.com>
Diffstat (limited to 'core')
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java17
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java30
2 files changed, 44 insertions, 3 deletions
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 89815c3e5e..6fcac39eb3 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 6e73fea332..0bcab92ea2 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<void (*)(int)>(&someAction);
+ //}
+
+ //void someAction(int i) {
+ //}
+ //int foo() {
+ // auto f = static_cast<void (*)(int)>(&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();
+ }
}

Back to the top