[Issue 1341] New: typeof(int) should probably be legal
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sat Jul 14 14:52:04 PDT 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1341
Summary: typeof(int) should probably be legal
Product: D
Version: 1.018
Platform: PC
OS/Version: Windows
Status: NEW
Severity: normal
Priority: P2
Component: DMD
AssignedTo: bugzilla at digitalmars.com
ReportedBy: clugdbug at yahoo.com.au
According to the spec (in declaration.html), the argument to typeof() must be
an expression. This is not currently enforced by DMD. In fact, it can be any
type, except for builtin types which fail with a misleading error message.
alias int foo;
typeof(foo) a; // ok
typeof(int) b; // FAILS: found ')' when expecting '.' following 'int'
typeof(typeof(foo)) c; // ok, even though the argument is obviously a type.
I think that the compiler's behaviour generally makes more sense than the spec
(and I'm finding it to be useful behaviour). Enforcing the rule in the spec
would mean the compiler would need to determine if 'foo' is a type name before
issuing a syntax error --> violation of independence of syntax and semantic
passes.
So I suggest that the spec be changed to allow typeof(Type) to be legal, and to
adjust the compiler to accept built-in types.
eg, make typeof(int) synonymous with int.
--
More information about the Digitalmars-d-bugs
mailing list