From 69fb4ee9cd406b9fc0d4056cba5d7de18d398f30 Mon Sep 17 00:00:00 2001 From: Nathan Ridge Date: Tue, 26 Jul 2016 00:27:10 -0400 Subject: [PATCH] Bug 498434 - Floating-point literal with leading zero Change-Id: I7417405ae89b41c7d3b28089320cc66f1c7c6173 --- .../core/parser/tests/ast2/AST2CPPTests.java | 8 ++++++ .../parser/cpp/CPPASTLiteralExpression.java | 26 ++++++++++++++----- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java index 1d14273bbe6..6bdfb3a48c5 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java @@ -11785,6 +11785,14 @@ public class AST2CPPTests extends AST2TestBase { assertTrue(test.getType() instanceof IProblemType); // resolution is ambiguous } + // double waldo1 = 02.968; + // double waldo2 = 09.268; + // double waldo3 = 02e2; + // double waldo4 = 09e2; + public void testFloatLiteralWithLeadingZero_498434() throws Exception { + parseAndCheckImplicitNameBindings(); + } + // char foo() { // return '*'; // } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTLiteralExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTLiteralExpression.java index 460be69100e..c1acbd086c1 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTLiteralExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTLiteralExpression.java @@ -444,8 +444,12 @@ public class CPPASTLiteralExpression extends ASTNode implements ICPPASTLiteralEx while (Character.isDigit(c) && i < fValue.length) { c = fValue[++i]; } - return i; } + + /* + * A floating-point constant could also have a leading zero + */ + return handleDecimalOrExponent(c, i); } else if (Character.isDigit(c)) { /* decimal-literal : * nonzero-digit (c has to be this to get into this else) @@ -455,12 +459,8 @@ public class CPPASTLiteralExpression extends ASTNode implements ICPPASTLiteralEx while (Character.isDigit(c) && i < fValue.length) { c = fValue[++i]; } - - if (c == '.') { - return afterDecimalPoint(i); - } else if ((c | 0x20) == 'e') { - return exponentPart(i); - } + + return handleDecimalOrExponent(c, i); } else { // Somehow we got called and there wasn't a digit // Shouldn't get here @@ -470,6 +470,18 @@ public class CPPASTLiteralExpression extends ASTNode implements ICPPASTLiteralEx return i; } + /* + * Consumes a decimal point or exponent, if present. + */ + private int handleDecimalOrExponent(char c, int i) { + if (c == '.') { + return afterDecimalPoint(i); + } else if ((c | 0x20) == 'e') { + return exponentPart(i); + } + return i; + } + /* * Called with the expectation that fValue[i] == '.' */