01777777777777777777777 [std.conv.octal]

kdevel kdevel at vogtner.de
Thu Apr 7 14:00:37 UTC 2022


On Thursday, 7 April 2022 at 12:52:20 UTC, MoonlightSentinel 
wrote:
> On Wednesday, 6 April 2022 at 20:27:10 UTC, kdevel wrote:
>> Does it *feel* wrong to you, too?
>
> Yes. I've changed to hint s.t. it suggests the string version. 
> [PR](https://github.com/dlang/dmd/pull/13958)

Commendable, but my question related to the implementation

```
template octal(alias decimalInteger)
if (is(typeof(decimalInteger)) && 
isIntegral!(typeof(decimalInteger)))
{
     enum octal = 
octal!(typeof(decimalInteger))(to!string(decimalInteger));
}
```

For this code I can hardly imagine an enhancement in order to 
cover decimalInteger > ulong.max. There is also a naming issue: 
Do we name parameters after their representation (decimal) or 
after their function (octal)? A better name is probably 
``octalLiteralDisguisedAsDecimalLiteral``.

The documentation [1], [2] does not explicitly mention the 
inherent limitation of the quoteless conversion. The two forms 
``octal!<literal>`` and ``octal!<literal>"`` are treated as 
interchangeable. In [3] we read

4. C-style octal integer notation was deemed too easy to mix up 
with decimal notation; it is only fully supported in string 
literals. D still supports octal integer literals interpreted at 
compile time through the std.conv.octal template, as in octal!167.

There is no mention of any restriction of the argument domain at 
all.

**TL;DR**: Deprecate and remove template octal(alias 
decimalInteger).

[1] <https://dlang.org/library/std/conv/octal.html>
[2] <https://dlang.org/phobos/std_conv.html#octal>
[3] <https://dlang.org/spec/lex.html#integerliteral>


More information about the Digitalmars-d mailing list