From c0cbc9010d0438a8a898aa653be3c56c73a755d2 Mon Sep 17 00:00:00 2001 From: Anton Leherbauer Date: Thu, 22 Jan 2009 10:33:11 +0000 Subject: [PATCH] Bug 261967 - Format produces error for __attribute__ ((__unused__)) flag --- .../cdt/internal/formatter/CodeFormatterVisitor.java | 1 - .../src/org/eclipse/cdt/internal/formatter/Scribe.java | 5 ++++- .../ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java | 6 ++++++ 3 files changed, 10 insertions(+), 2 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 883bdb5b261..bc00a51b600 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 @@ -436,7 +436,6 @@ public class CodeFormatterVisitor extends CPPASTVisitor { // declarator final IASTDeclarator declarator= node.getDeclarator(); if (declarator != null) { - skipNonWhitespaceToNode(declarator); boolean needSpace= declarator.getPointerOperators().length > 0 && scribe.printComment(); if (needSpace) { scribe.space(); diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/Scribe.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/Scribe.java index 82b59eb7d71..00995509256 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/Scribe.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/Scribe.java @@ -1709,9 +1709,12 @@ public class Scribe { fSkippedIndentations--; } } else if (offset > currentPosition) { - printComment(); + boolean hasSpace= printComment(); final int nextPosition= scanner.getCurrentPosition(); if (offset > nextPosition) { + if (hasSpace) { + space(); + } printRaw(nextPosition, offset - nextPosition); scanner.resetTo(offset, scannerEndPosition - 1); } 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 7f9cad4ee4b..f5e41b4d07f 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 @@ -1130,4 +1130,10 @@ public class CodeFormatterTest extends BaseUITestCase { assertFormatterResult(); } + //bool member __attribute__ ((__unused__)) = false; + + //bool member __attribute__ ((__unused__)) = false; + public void testPreserveSpaceBetweenNameAnd__attribute__Bug261967() throws Exception { + assertFormatterResult(); + } }