D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 4602 - Header generation turns 'typeof(x)(...)' into C-style cast
Summary: Header generation turns 'typeof(x)(...)' into C-style cast
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: Other All
: P2 critical
Assignee: No Owner
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2010-08-09 03:48 UTC by Lars T. Kyllingstad
Modified: 2010-08-26 13:25 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Lars T. Kyllingstad 2010-08-09 03:48:33 UTC
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
Comment 1 Don 2010-08-26 13:25:35 UTC
Fixed http://www.dsource.org/projects/dmd/changeset/629
as part of bug 4713.