Bug 4602 – Header generation turns 'typeof(x)(...)' into C-style cast
Status
RESOLVED
Resolution
FIXED
Severity
critical
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
All
Creation time
2010-08-09T03:48:00Z
Last change time
2010-08-26T13:25:35Z
Keywords
wrong-code
Assigned to
nobody
Creator
bugzilla
Comments
Comment #0 by bugzilla — 2010-08-09T03:48:33Z
When typeof(x)(...) is used as a struct literal, the compiler adds parentheses around typeof(x) in the generated .di file. When the .di file is later used, the compiler interprets (typeof(x)) as a C-style cast.
I tend to use
return typeof(return)(...);
a lot in generic code, and this issue makes header files completely unusable to me.
Test case:
$ cat test.d
struct S { int i; }
S foo() { return typeof(return)(123); }
$ dmd -c -o- -H test.d
$ cat test.di
// D import file generated from 'test.d'
struct S
{
int i;
}
S foo()
{
return (typeof(return))(123);
}
$ dmd -c -o- test.di
test.di(8): C style cast illegal, use cast(typeof(return))123