On Tuesday, October 28, 2014 00:31:43 Domingo via Digitalmars-d-learn wrote: > Hello ! > > I'm not sure if I'm missing something here but for a tagged enum > it doesn't seem to make sense to forbid reserved keywords like: > > enum CrudOps {read, write, delete} > > The dmd compiler are complaining: > ------ > cte.d(4): Error: basic type expected, not delete > cte.d(4): Error: no identifier for declarator int > cte.d(4): Error: type only allowed if anonymous enum and no enum > type > cte.d(4): Error: if type, there must be an initializer > cte.d(4): Error: found 'delete' when expecting ',' > ------ > > It doesn't make sense to me because this kind of enum will not > polute the global space and always need to beused with the tag: > CrudOps.delete > > I'm missing something here ?
keywords are always keywords wherever they are in the code and are only legal where those keywords are legal. I can see how you could come to the conclusion that the compiler shouldn't think that you're trying to use a keyword as an enum member, but the compiler does not take that into account. And I've never seen a language where it did (though one may exist out there somewhere). The thing that's been done in Phobos in this type of situation is to put an underscore on the end of the keyword, so you'd get enum CrudOps { read, write, delete_ } and while that may not be what you want, it's pretty much the best that you can do. - Jonathan M Davis