Thread overview
[Issue 20479] octal integer literals don't work with BetterC mode
Jan 18, 2020
Mathias LANG
Jun 18, 2021
Heromyth
Jun 18, 2021
mipri
Dec 17, 2022
Iain Buclaw
Jan 15, 2023
Walter Bright
January 04, 2020
https://issues.dlang.org/show_bug.cgi?id=20479

Dominikus Dittes Scherkl <dominikus@scherkl.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dominikus@scherkl.de

--- Comment #1 from Dominikus Dittes Scherkl <dominikus@scherkl.de> ---
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.

--
January 18, 2020
https://issues.dlang.org/show_bug.cgi?id=20479

Mathias LANG <pro.mathias.lang@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |betterC
                 CC|                            |pro.mathias.lang@gmail.com
           Hardware|x86                         |All
                 OS|Mac OS X                    |All
           Severity|enhancement                 |normal

--- Comment #2 from Mathias LANG <pro.mathias.lang@gmail.com> ---
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.

--
June 18, 2021
https://issues.dlang.org/show_bug.cgi?id=20479

--- Comment #3 from Heromyth <bitworld@qq.com> ---
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
```

--
June 18, 2021
https://issues.dlang.org/show_bug.cgi?id=20479

mipri <mipri@minimaltype.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |CTFE
                 CC|                            |mipri@minimaltype.com

--- Comment #4 from mipri <mipri@minimaltype.com> ---
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.

--
December 17, 2022
https://issues.dlang.org/show_bug.cgi?id=20479

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P1                          |P3

--
January 15, 2023
https://issues.dlang.org/show_bug.cgi?id=20479

Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla@digitalmars.com
         Resolution|---                         |FIXED

--- Comment #5 from Walter Bright <bugzilla@digitalmars.com> ---
This is working in master now.

--