From 2bb6839c1ad236c4f733e271885a86e396bfc956 Mon Sep 17 00:00:00 2001 From: Marco Stornelli Date: Sat, 2 Mar 2019 15:29:19 +0100 Subject: Bug 540252: Fix formatting operator< with explicit instantiation A space must be forced in this special case even if preferences say something different. Change-Id: Ie43b988139913f87590f4f1460d28e79f9bd7ef8 Signed-off-by: Marco Stornelli --- .../internal/formatter/CodeFormatterVisitor.java | 8 ++++++-- .../cdt/ui/tests/text/CodeFormatterTest.java | 23 ++++++++++++++++++++++ 2 files changed, 29 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 1e402ba02bd..cd502b3f7ef 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 @@ -3570,8 +3570,12 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, IASTName name = node.getTemplateName(); name.accept(this); if (peekNextToken() == Token.tLT) { - scribe.printNextToken(Token.tLT, - preferences.insert_space_before_opening_angle_bracket_in_template_arguments); + char[] simpleId = name.getSimpleID(); + if (simpleId[simpleId.length - 1] == '<') + scribe.printNextToken(Token.tLT, true); + else + scribe.printNextToken(Token.tLT, + preferences.insert_space_before_opening_angle_bracket_in_template_arguments); if (preferences.insert_space_after_opening_angle_bracket_in_template_arguments) { scribe.space(); } 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 d17b169fa64..ec166d5bfa2 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 @@ -3758,4 +3758,27 @@ public class CodeFormatterTest extends BaseUITestCase { public void testTemplateIdWithMacro4_Bug406231() throws Exception { assertFormatterResult(); } + + //class data + //{ + //public: + // template bool operator< (x const &n) const + // { + // return n < 0; + // } + //}; + ////explicit instantiation + //template bool data::operator< (int const &) const; + + //class data { + //public: + // template bool operator<(x const &n) const { + // return n < 0; + // } + //}; + ////explicit instantiation + //template bool data::operator< (int const &) const; + public void testTemplateInstantiationOperatorLesser_Bug540252() throws Exception { + assertFormatterResult(); + } } -- cgit v1.2.3