Bug 11554 – `is(T == enum);` produces an error if T is an enum defined with no members
Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-11-19T09:31:00Z
Last change time
2013-11-30T09:09:49Z
Keywords
pull, rejects-valid
Assigned to
nobody
Creator
blah38621
Comments
Comment #0 by blah38621 — 2013-11-19T09:31:10Z
The following code now produces an error, when it previously produced no error. The error can be eliminated by adding a member to the enum, but that's not how every enum that I've seen that's intended as a UDA is declared.
enum isEnum(T) = is(T == enum);
@safe pure nothrow unittest
{
enum AnEnum;
static assert(isEnum!AnEnum, "Failed to determine that AnEnum is an enum!");
}
And now the error:
std/traitsExt.d(43): Error: enum std.traitsExt.__unittestL44_9.AnEnum is forward referenced looking for base type.
As far as I can tell, it was caused by the commit merged in https://github.com/D-Programming-Language/dmd/pull/2795. However, without some fun with git I can't be certain, but it's the only commit dealing with enums in the last 2 days, before which this code compiled without error.
Here is another test case. The bug still shows up if the member-less enum is in another module. Works with version 2.064. Fails with github head.
$ dmd test.d
test.d(2): Error: enum test.zoo is forward referenced looking for base type
// File frop.d
module frop;
struct bro(N...) {}
size_t foo(size_t I=0, T)(T t) {
static if(I == t.tupleof.length) return 0;
else {
if(baz!(0, -1, __traits(getAttributes, t.tupleof[I]))) foo!(I+1)(t);
return foo!(I+1)(t);
}
}
template baz(size_t C, int P, A...) {
static if(A.length == 0) enum baz = P;
else static if(is(A[0] unused: bro!M, M...)) {}
else enum baz = baz!(C+1, P, A[1..$]);
}
// File test.d
import frop;
enum zoo;
class Bar { @zoo ubyte pop; }
void main() { foo(new Bar); }
Comment #4 by k.hara.pg — 2013-11-27T02:26:50Z
(In reply to comment #3)
> Here is another test case. The bug still shows up if the member-less enum is in
> another module. Works with version 2.064. Fails with github head.
Reduced case:
enum zoo;
struct bro(N...) {}
static assert(!is(zoo unused : bro!M, M...));
https://github.com/D-Programming-Language/dmd/pull/2889