www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 8275] New: DMD assumes that Object.toHash() overrides are safe, even though base is trusted

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

           Summary: DMD assumes that Object.toHash() overrides are  safe,
                    even though base is  trusted
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: minor
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: alex lycus.org



CEST ---
class A
{
    override hash_t toHash() pure nothrow const
    {
        return *cast(hash_t*)&main;
    }
}

void main()
{
}

test.d(5): Error: cast from void function() to uint* not allowed in safe code

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 20 2012
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8275


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID



This is an expected behavior of attribute inference with inheritance.

class A {
    void foo()  trusted {}
}
class B : A {
    override void foo() {
        int n;
        //auto p = cast(int*)n;  // not allowed in safe code
    }
}
void main() {
    pragma(msg, typeof(A.foo)); // prints " trusted void()"
    pragma(msg, typeof(B.foo)); // prints " safe void()" !
}

When you inherit a  trusted method, the derived method that you write is
inferred as  safe.
In other words, if you want to write  trusted code, you should qualify the
method with  trueted attribute.

class B : A {
    override void foo()  trusted {
        int n;
        auto p = cast(int*)n;  // allowed in trusted code
    }
}

It seems to me that is necessary to avoid accidentally breaking of  safe
system.

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