Bug 3251 – DecimalFloat literal cannot begin with "08" or "09"
Status
RESOLVED
Resolution
FIXED
Severity
minor
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Windows
Creation time
2009-08-15T04:51:45Z
Last change time
2019-10-10T12:33:57Z
Keywords
rejects-valid
Assigned to
No Owner
Creator
Stewart Gordon
Comments
Comment #0 by smjg — 2009-08-15T04:51:45Z
DecimalFloat:
DecimalDigits .
DecimalDigits . DecimalDigits
DecimalDigits . DecimalDigits DecimalExponent
. Decimal
. Decimal DecimalExponent
DecimalDigits DecimalExponent
DecimalDigits:
DecimalDigit
DecimalDigit DecimalDigits
DecimalDigit:
0
NonZeroDigit
_
Going by this, floating point literals are the same whether they begin with a 0 or not, unlike integer literals. Code that illustrates this fact:
----------
pragma(msg, (76).stringof);
pragma(msg, (076).stringof);
pragma(msg, (76.).stringof);
pragma(msg, (076.).stringof);
pragma(msg, (76.543).stringof);
pragma(msg, (076.543).stringof);
pragma(msg, (678.).stringof);
pragma(msg, (0678.).stringof);
pragma(msg, (876.543).stringof);
//pragma(msg, (0876.543).stringof);
----------
76
62
76
76
76.543
76.543
678
678
876.543
----------
However, if the final, commented-out line is reinstated, I get errors:
----------
float_literal.d(10): found '876.543' when expecting ')'
float_literal.d(10): no identifier for declarator .stringof
float_literal.d(10): semicolon expected, not ')'
float_literal.d(10): Declaration expected, not ')'
----------
Presumably, DMD sees the '0' and begins trying to lex it as an Octal, but fails to recover properly when it stumbles upon the '8'. But it's strange that other similar forms compile successfully, such as the aforementioned "0678.", "008." and "0_9.".
Comment #1 by razvan.nitu1305 — 2019-10-10T12:33:57Z
Currently, when dmd sees a 0 it starts parsing an octal. If it finds any digit > 7 it errors. However, if it finds a point, it immediately switches to parsing a floating point literal, thus accepting from this point digits larger than 7:
07341 => octal
07238 => error
024.8 => foating point literal
I think this is fine.