Bug 19059 – Invalid integer literal 08 and 09 allowed

Status
RESOLVED
Resolution
FIXED
Severity
trivial
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2018-07-04T20:54:59Z
Last change time
2018-08-24T15:02:04Z
Assigned to
No Owner
Creator
Hiroki Noda

Comments

Comment #0 by kubo39 — 2018-07-04T20:54:59Z
--- void main() { assert(08 == 8); // can compile and run. assert(09 == 9); }
Comment #1 by ag0aep6g — 2018-07-04T23:23:51Z
Per the spec [1], `01` through `09` are all invalid since octal literals are gone. They all have obvious values, though. Which is probably why they've been kept around. I see three ways forward: 1) Outlaw `01` through `09`. This would break existing code. 2) Let all literals that start with zero be decimals instead of octals. `01` would be 1, `08` would be 8, `000123` would be 123. This would break the rule that C code should either behave the same or fail compilation in D. 3) Allow only `01` through `09` as decimal literals. Not elegant, but it might be the best option. [1] https://dlang.org/spec/lex.html#DecimalInteger
Comment #2 by slavo5150 — 2018-07-04T23:52:03Z
If octal literals are gone, I vote for (2). I don't think we should be too draconian about such C compatibility rules, especially to accommodate octals, which are even an oddity in C.
Comment #3 by pro.mathias.lang — 2018-07-05T01:39:16Z
@ag0aep0g: AFAICS, solution 3 is what's currently implemented.
Comment #4 by ag0aep6g — 2018-07-05T08:16:31Z
(In reply to Mathias LANG from comment #3) > @ag0aep0g: AFAICS, solution 3 is what's currently implemented. In DMD, yeah. For #3, the spec would need to be updated.
Comment #5 by kubo39 — 2018-07-05T11:56:08Z
I am concerned about (2) and (3), is this behavior confusing with the use of std.conv. octal? --- assert(010 == 10); // Error: octal literals 010 are no longer supported, use std.conv.octal!10 instead assert(019 == 19); // Error: radix 8 digit expected, not 9 // Error: octal literals 021 are no longer supported, use std.conv.octal!21 instead
Comment #6 by razvan.nitu1305 — 2018-07-05T18:49:46Z
Comment #7 by kubo39 — 2018-07-08T13:08:01Z
I created another issue for invalid octal literals `01` through `07`. https://issues.dlang.org/show_bug.cgi?id=19070
Comment #8 by github-bugzilla — 2018-07-12T14:30:25Z
Commits pushed to master at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/90ab1b325f26d08bd770cd9fd44bed085c775ad9 Fix Issue 19059 - Disallow `08` and `09` in integer literal https://github.com/dlang/dmd/commit/cdedafdd22b6eb2dd5eb550d913c851d11dd28dc Merge pull request #8451 from kubo39/disallow-invalid-octal-digital Fix Issue 19059 - Disallow `08` and `09` in integer literal merged-on-behalf-of: Steven Schveighoffer <[email protected]>
Comment #9 by schveiguy — 2018-08-24T15:02:04Z
*** Issue 16396 has been marked as a duplicate of this issue. ***