The following code bypasses immutabililty with GDC but not DMD
Manu
turkeyman at gmail.com
Thu Apr 11 19:35:41 PDT 2013
This is an interesting problem with the ref-is-not-part-of-the-type design.
You can't really have a const(ref) in D, and a ref const(int) is kinda
backwards logic.
I've never understood why ref isn't part of the type... can someone explain
why this is a good thing? It seems to cause all sorts of troublesome
problems... auto ref in templates for one.
On 12 April 2013 10:50, Nicholas Smith <nmsmith65 at gmail.com> wrote:
> I don't know how to file bug reports but I'm sure this shouldn't happen :)
> DMD gives an error.
>
> import std.stdio;
>
> void main()
> {
> immutable Cat cat = cast(immutable) new Cat(5);
> happyBirthday(cat.age);
> writefln("My 5 year old cat is %s years old!", cat.age);
> }
>
> void happyBirthday(ref int i)
> {
> i++;
> }
>
> class Cat
> {
> public int age;
>
> this(int a)
> {
> this.age = age;
> }
> }
>
>
> Output:
> My 5 year old cat is 6 years old!
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/d.gnu/attachments/20130412/52eacfe3/attachment.html>
More information about the D.gnu
mailing list