https://issues.dlang.org/show_bug.cgi?id=12753
Kenji Hara <[email protected]> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution|--- |INVALID --- Comment #1 from Kenji Hara <[email protected]> --- (In reply to bearophile_hugs from comment #0) > import std.traits: EnumMembers; > enum Foo { A, B, C } > int bar1(immutable Foo x) { > foreach (immutable pos, immutable y; EnumMembers!Foo) > if (x == y) > return pos; > } > int bar2(immutable Foo x) { > foreach (immutable pos, immutable y; [EnumMembers!Foo]) > if (x == y) > return pos; > } > void main() {} > > > With dmd 2.066alpha gives errors: > > temp.d(3,5): Error: function temp.bar1 no return exp; or assert(0); at end > of function > temp.d(8,5): Error: function temp.bar2 no return exp; or assert(0); at end > of function > > > But I think the D compiler should be able to understand that a foreach on > the whole range of an enum (found with EnumMembers) covers its all possible > values, so those two functions always return a value and don't need the > assert(0) at the end. It's wrong assumption. By using cast, you can give undefined enum value to bar1 and bar2. bar1(cast(Foo)99); bar2(cast(Foo)99); Therefore, the compiler error is legitimate. --
