D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 10503 - Octal enums don't work anymore
Summary: Octal enums don't work anymore
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 regression
Assignee: No Owner
URL:
Keywords: pull, rejects-valid
Depends on:
Blocks:
 
Reported: 2013-06-29 10:47 UTC by hsteoh
Modified: 2013-06-30 06:05 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description hsteoh 2013-06-29 10:47:52 UTC
CODE:
=============================
import std.conv;
enum {
	A = octal!"2000000",
	B = octal!"4000"
}

void main() {
}
=============================

DMD git HEAD:
=============================
test.d(4): Error: cannot implicitly convert expression (octal) of type pure nothrow @property @safe int() to pure nothrow @property @safe int()
=============================

git bisect shows that the offending commit was 88ebe192d605bd8d4b5768e8a2500f54d73fb5fd
Comment 1 Henning Pohl 2013-06-29 11:37:12 UTC
You need to execute octal by using parentheses:

import std.conv;

enum {
    A = octal!"2000000"(),
    B = octal!"4000"()
}

void main() {
}

As the compiler has mentioned, what you have actually been doing is passing functions instead of their result when executed.

What you could possibly do to avoid these parentheses is using eponymous templates.
Comment 2 Andrej Mitrovic 2013-06-29 12:12:39 UTC
(In reply to comment #1)
> You need to execute octal by using parentheses.

No you don't, this is a breaking change that needs to be fixed. octal has always been used like this.
Comment 3 Adam D. Ruppe 2013-06-29 12:14:31 UTC
octal isn't even a function, I thought. It uses a helper function internally, but in the end does an

template octal(s) {
   enum octal = helper(s);
}

so calling it on the outside world isn't right - octal!100 should be an int literal.
Comment 4 Henning Pohl 2013-06-29 12:27:33 UTC
Guess you are right. I'm working on this.
Comment 5 hsteoh 2013-06-29 13:23:36 UTC
This problem only happens when the enum has two members. Manifest constants and single-member enums work fine. So it's definitely a bug (inconsistent behaviour between single-member and multi-member enums).
Comment 6 Henning Pohl 2013-06-29 13:43:29 UTC
https://github.com/D-Programming-Language/dmd/pull/2277

Kind of dirty fix, but it will do it for now.
Comment 7 Kenji Hara 2013-06-30 01:07:00 UTC
(In reply to comment #6)
> https://github.com/D-Programming-Language/dmd/pull/2277
> 
> Kind of dirty fix, but it will do it for now.

I opened another fix that I think clean.
https://github.com/D-Programming-Language/dmd/pull/2279
Comment 8 github-bugzilla 2013-06-30 03:28:34 UTC
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/f88c75f17dcc25ace5d8a52a4a9f5e6d301ad8a4
fix Issue 10503 - Octal enums don't work anymore

https://github.com/D-Programming-Language/dmd/commit/e8c76cdd192676613a37b5faaf7f3d6c758ef42d
Merge pull request #2279 from 9rnsr/fix10503

[REG2.064a] Issue 10503 - Octal enums don't work anymore