[dmd-beta] D 1.074 and 2.059 betas 2

Walter Bright walter at digitalmars.com
Sat Apr 7 15:14:35 PDT 2012



On 4/7/2012 2:21 PM, Nick Sabalausky wrote:
> From: "Nick Sabalausky" <bus_dmdbeta at semitwist.com>
>> While the test case for #7826 now works, for some reason I'm still getting 
>> the same warning in my own projects (but without "pure" being included in 
>> "must be declared as...") even though they which use the *exact* same toHash 
>> function (well, except "str" having a different name). I'll try to figure out 
>> a new test case after I get some sleep...
>>
>
> /facepalm: With Beta2, I wasn't getting the probelem with the original test 
> case (ie "const hash_t toHash()") because I wasn't compiling it with warnings 
> enabled.
>
> So here's the "issue" now, *if* it even is an issue (I'm not sure):
>
> With Beta2's current fix for #7826, I can do this without warnings or errors:
>
>    struct Foo {
>        string str;
>        const nothrow @safe hash_t toHash() {
>            return typeid(string).getHash(&str);
>        }
>    }
>
> But, this (ie, removing nothrow and/or @safe):
>
>    struct Foo {
>        string str;
>        const hash_t toHash() {
>            return typeid(string).getHash(&str);
>        }
>    }
>
> Gives me a warning:
>
> Warning: toHash() must be declared as extern (D) uint toHash() const nothrow 
> @safe, not const uint()
>
> Is this the correct behavior or not? Jonathan's comment over here ( 
> http://d.puremagic.com/issues/show_bug.cgi?id=7826 ) suggested that toHash in 
> a struct shouldn't require nothrow or @safe. I'm refraining from having any 
> opinion on the matter ATM, I just wanted to bring it up in case the current 
> fix is incomplete.
>

It's correct behavior. We're moving towards const/pure/nothrow/@safe for all 
those functions.


More information about the dmd-beta mailing list