[Issue 4602] New: Header generation turns 'typeof(x)(...)' into C-style cast

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Aug 9 03:48:37 PDT 2010


http://d.puremagic.com/issues/show_bug.cgi?id=4602

           Summary: Header generation turns 'typeof(x)(...)' into C-style
                    cast
           Product: D
           Version: D2
          Platform: Other
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: bugzilla at kyllingen.net


--- Comment #0 from Lars T. Kyllingstad <bugzilla at kyllingen.net> 2010-08-09 03:48:33 PDT ---
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

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list