From 3113871624d733abf81b4efd24cce957f25ef6c3 Mon Sep 17 00:00:00 2001 From: Marco Stornelli Date: Wed, 6 Mar 2019 19:08:17 +0100 Subject: [PATCH] Bug 543947: Fix exception while formatting macro Change-Id: If3e1a4da919c4e7f78ca4506e97ea1f6f37f7c8c Signed-off-by: Marco Stornelli --- .../formatter/CodeFormatterVisitor.java | 3 +- .../cdt/ui/tests/text/CodeFormatterTest.java | 30 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) 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 cd502b3f7ef..2129e9d44f1 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 @@ -3556,7 +3556,8 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, } for (ICPPASTNameSpecifier nameSpec : node.getQualifier()) { nameSpec.accept(this); - scribe.printNextToken(Token.tCOLONCOLON); + if (peekNextToken() == Token.tCOLONCOLON) + scribe.printNextToken(Token.tCOLONCOLON); } if (peekNextToken() == Token.tCOMPL) { // destructor 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 ec166d5bfa2..8f133335978 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 @@ -3781,4 +3781,34 @@ public class CodeFormatterTest extends BaseUITestCase { public void testTemplateInstantiationOperatorLesser_Bug540252() throws Exception { assertFormatterResult(); } + + //#define WW(x) std::ostringstream(x) + //namespace some_namespace + //{ + // void func() + // { + // try + // { + // WW("1") << "2"; + // } + // catch (const std::exception& e) + // { + // std::cout << "blah...." << std::endl; + // } + // } + //} + + //#define WW(x) std::ostringstream(x) + //namespace some_namespace { + //void func() { + // try { + // WW("1") << "2"; + // } catch (const std::exception& e) { + // std::cout << "blah...." << std::endl; + // } + //} + //} + public void testFormmatterWithMacro_Bug543947() throws Exception { + assertFormatterResult(); + } }