bug in typeof or wrong enum specs?

Dicebot public at dicebot.lv
Wed Aug 28 16:49:41 PDT 2013


On Wednesday, 28 August 2013 at 23:28:14 UTC, captaindet wrote:
> a recent discussion ( 
> http://forum.dlang.org/thread/kvje4r$1tff$1@digitalmars.com ) 
> about the official enum dox ( http://dlang.org/enum.html ) was 
> not conclusive whether
>
> 	enum IDENTIFIER;
>
> is officially allowed/supported. jacob pointed out that it has 
> an important use case in that it can serve as UDA. as UDAs are 
> fairly new, this cannot be the reason why this syntax was 
> allowed in the first place though, *if* it is allowed. also, it 
> might be used in meta stuff similar to "#define IDENTIFIER" in 
> C - playing with this idea i run into this issue...
>
> while much code behaves with such an empty enum declaration,
>
> 	writeln( __traits(compiles, IDENTIFIER) );	// true
> 	writeln( is( IDENTIFIER == enum ) );			// true
>
> typeof() is not happy at all (DMD 2.063.2):
>
> 	writeln( typeof(IDENTIFIER).stringof );		
> 	// Error: argument IDENTIFIER to typeof is not an expression
>
> typeof() expects an expression and a bare identifier is a 
> "PrimaryExpression" ( 
> http://dlang.org/expression.html#PrimaryExpression ) and hence 
> a valid argument.
>
> either the empty enum declaration is not allowed (and should be 
> removed from the dox and throw a compilation error) or there is 
> a bug in typeof().
>
>
> /det

typeof only accepts expressions, not types. enum symbol acts as a 
type here as it does not have associated value (typeof(int) will 
result in same error message)


More information about the Digitalmars-d mailing list