www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 217] New: typeof not working properly in internal/object.d

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=217

           Summary: typeof not working properly in internal/object.d
           Product: D
           Version: 0.161
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P3
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: sean f4.ca


This bug appears related to the special handling DMD seems to have for
compiling the object.d implementation file: internal/object.d.  If the version
blocks used to generate size_t and ptrdiff_t aliases (ie. lines 48-73) are
removed and replaced by the more flexible aliases used in the global object.d
header file:

    alias typeof(int.sizeof) size_t;
    alias typeof(cast(void*)0 - cast(void*)0) ptrdiff_t;
    alias size_t hash_t;

Then attempting to rebuild Phobos will generate these errors:

\bin\dmd\bin\dmd -c -O -release -nofloat -w internal\object.d
internal\object.d(388): function object.memcpy (void*,void*,typeof(4u)) does
not match argument types (ubyte*,void*,uint)
internal\object.d(388): cannot implicitly convert expression (sz) of type uint
to typeof(4u)
internal\object.d(389): function object.memcpy (void*,void*,typeof(4u)) does
not match argument types (void*,void*,uint)
internal\object.d(389): cannot implicitly convert expression (sz) of type uint
to typeof(4u)
internal\object.d(390): function object.memcpy (void*,void*,typeof(4u)) does
not match argument types (void*,ubyte*,uint)
internal\object.d(390): cannot implicitly convert expression (sz) of type uint
to typeof(4u)
internal\object.d(537): function object.memcmp (void*,void*,typeof(4u)) does
not match argument types (void*,void*,uint)
internal\object.d(537): cannot implicitly convert expression (this.xsize) of
type uint to typeof(4u)
internal\object.d(555): function object.memcmp (void*,void*,typeof(4u)) does
not match argument types (void*,void*,uint)
internal\object.d(555): cannot implicitly convert expression (this.xsize) of
type uint to typeof(4u)

--- errorlevel 1

I can't reproduce this elsewhere so I'm marking this bug as low priority, but
it should probably be fixed at some point.


-- 
Jun 22 2006
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=217





------- Comment #1 from braddr puremagic.com  2007-09-17 00:55 -------
It looks like it's a forward declaration issue with respect to alias and
extern(C) functions.  As long as the alias is before the extern(C) functions
that use the aliases, it's fine.  For example, calloc uses size_t.  In the next
attachment is a diff against dmd 1.021's internal/object.d that builds
successfully.

This isn't to say that there isn't a bug here, since order isn't supposed to
matter, right?


-- 
Sep 16 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=217





------- Comment #2 from braddr puremagic.com  2007-09-17 00:55 -------
Created an attachment (id=182)
 --> (http://d.puremagic.com/issues/attachment.cgi?id=182&action=view)
change to using a less version specific set of aliases


-- 
Sep 16 2007
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=217





------- Comment #3 from braddr puremagic.com  2007-10-20 03:24 -------
The attachment was applied in 1.022/2.006, but the underlying but wasn't fixed.
 Here's a reduced test case for it:

---------
extern(C) void bar(foo b);
alias typeof(int.sizeof) foo;
void main() { bar(1); }
---------

results in:
bug217.d(3): function bug217.bar (typeof(4u)) does not match parameter types
(int)
bug217.d(3): Error: cannot implicitly convert expression (1) of type int to
typeof(4u)
bug217.d(3): Error: cannot cast int to typeof(4u)
bug217.d(3): Error: integral constant must be scalar type, not typeof(4u)

If the first two lines are reversed, it builds fine.


-- 
Oct 20 2007