Bug 20479 – octal integer literals don't work with BetterC mode

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P3
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-01-04T01:56:58Z
Last change time
2023-01-15T06:50:14Z
Keywords
betterC, CTFE
Assigned to
No Owner
Creator
Heromyth

Comments

Comment #0 by bitworld — 2020-01-04T01:56:58Z
import std.conv : octal; extern(C) void main() { enum a = octal!167; // bug enum b = octal!"167"; // ok }
Comment #1 by dominikus — 2020-01-04T15:48:57Z
This is not D_as_better_C specific. The octal template requires a string as template-parameter, because any other type would have already been interpreted as a decimal (e.g. decimal 167 would be converted to octal 347 which is very unexpected). So I think this bug report is invalid. String is necessary.
Comment #2 by pro.mathias.lang — 2020-01-18T09:53:01Z
Actually the issue is valid, but it would have been nice to post the error messages you're getting. First, using the op's code, we get the following error with the latest DMD (2.090.0): ``` dmd -betterC foo.d /usr/local/opt/dmd/include/dlang/dmd/std/array.d(965): Error: TypeInfo cannot be used with -betterC ``` Which is obviously wrong, as `octal` should not lead to code being emitted in the binary. Then, if we tweak the code a bit: ``` import core.stdc.stdio; import std.conv : octal; extern(C) void main() { enum b = octal!"167"; printf("Octal literal: %d\n", b); } ``` We get the following link error: ``` dmd -betterC -run foo.d Undefined symbols for architecture x86_64: "__D3std4conv14isOctalLiteralFNaNbNiNfxAyaZb", referenced from: __D3std4conv__T5octalTiZQjFNaNbNiNfxAyaZi in foo.o ld: symbol(s) not found for architecture x86_64 ``` Turning the symbol into a `static immutable` doesn't help either.
Comment #3 by bitworld — 2021-06-18T07:32:12Z
It totally does not work now with DMD 2.097.0. The latest error message: ``` /Library/D/dmd/src/phobos/std/array.d(982,49): Error: `TypeInfo` cannot be used with -betterC ``` OR ``` /Library/D/dmd/src/phobos/std/conv.d(4858,33): Error: array concatenation of expression `num ~ " is not an octal literal"` requires the GC which is not available with -betterC ```
Comment #4 by mipri — 2021-06-18T09:06:41Z
Issue #21492 seems to be the reason for the failure with octal!167 Issue #19268 has a lot of discussion that's relevant to octal!"167". This specific case can be fixed just in phobos by swapping -private T octal(T)(const string num) +private T octal(T, string num)() and changing callers to suit.
Comment #5 by bugzilla — 2023-01-15T06:50:14Z
This is working in master now.