www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 7826] New: [D2 Beta] Cannot use getHash in toHash without a warning

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

           Summary: [D2 Beta] Cannot use getHash in toHash without a
                    warning
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: regression
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: cbkbbejeap mailinator.com



02:25:46 PDT ---
This code works in 2.058, even with warnings enabled:

------------------------
struct Foo
{
    string str;

    const hash_t toHash()
    {
        return typeid(string).getHash(&str);
    }
}
------------------------

But in the 2.059 beta:

dmd -c -w test.d
test.d(5): Warning: toHash() must be declared as extern (D) uint toHash() const pure nothrow safe, not const uint() However, if the warning is is fixed, it *still* doesn't work: ------------------------ struct Foo { string str; const pure nothrow safe hash_t toHash() { return typeid(string).getHash(&str); } } ------------------------ testToHash.d(7): Error: pure function 'toHash' cannot call impure function 'getHash' testToHash.d(7): Error: & D12TypeInfo_Aya6__initZ.getHash is not nothrow testToHash.d(5): Error: function testToHash.Foo.toHash 'toHash' is nothrow yet may throw -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Apr 05 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7826




17:11:31 PDT ---
I don't know what the correct solution is supposed to be, but in any case it
should be possible to use getHash in toHash with warnings enabled.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 05 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7826


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clugdbug yahoo.com.au



Clearly if toHash() is required to be pure, getHash() must also be.
But I think it is unreasonable for the compiler to demand that toHash() be
pure, especially at the present time.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 06 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7826


Jonathan M Davis <jmdavisProg gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jmdavisProg gmx.com



PDT ---
I believe that tohash is among the functions which were decided must be  safe
const pure nothrow on classes. So, in that case, I would expect it to be
required (though not until Object is appropriately const-correct and whatnot).
But I don't see why  safe, const, pure, or nothrow should be required for
structs, since no inheritance is involved. With classes, with have to pick what
we want and use that for everything (possibly with some overloads which don't
have quite the same list of attributes), but structs don't have the same
requirements/restrictions.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 06 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7826




Commit pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/c324826ab425da4d2896b2d7abd97ebffcc0231b
fix Issue 7826 - [D2 Beta] Cannot use getHash in toHash without a warning

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 06 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7826


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla digitalmars.com
         Resolution|                            |FIXED


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