[Issue 8185] Pure functions and pointers

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Jun 4 09:33:35 PDT 2012


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



--- Comment #41 from Jonathan M Davis <jmdavisProg at gmx.com> 2012-06-04 09:35:33 PDT ---
> void g(size_t p, ref size_t) pure
>{
>    ++*cast(int*) p;
>}

You're casting a size_t to a pointer. That's breaking the type system. The
assertion is guaranteed to pass as long as you don't break the type system.
That's exactly the same as occurs when casting away const. When you subvert the
type system, the compiler can't guarantee anything. It's the _programmer's_ job
at that point to maintain the compiler's guarantees. The compiler is free to
assume that the programmer did not violate those guarantees. If you do, you've
created a bug. This is precisely the sort of thing that comes up when someone
is crazy enough to cast away const on somethnig and try and mutate it. Such an
example is ultimately irrelevant, precisely because it violates the type
system.

-- 
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