digitalmars.D.learn - [D2] const vs structs
- Richard Webb (36/36) Dec 10 2009 I just tried to build the Juno library with DMD 2.037, and got a bunch o...
- Steven Schveighoffer (14/50) Dec 11 2009 It's due to this change: http://www.dsource.org/projects/dmd/changeset/2...
- Steven Schveighoffer (4/5) Dec 11 2009 Clarifying, I meant it is a bug in the compiler *not* in Juno :)
- Richard Webb (3/3) Dec 11 2009 Opened as 3606 and 3607.
I just tried to build the Juno library with DMD 2.037, and got a bunch or errors like: juno\com\core.d(295): Error: function juno.com.core.GUID.opEquals type signature should be const bool(ref const(GUID)) not bool(GUID other) Which can be replicated with: //////////////////////////////// struct Foo { bool opEquals(Foo f) const { return true; } } void Bar() { Foo f; } //////////////////////////////// It built ok with DMD2 a few months ago. Is this an intentional change? Also, while looking at the problem i noticed that code like: //////////////////////////////// struct Foo { ~this() { } } void Bar() { const Foo f; } //////////////////////////////// Produces the error: Error: destructor Foo.~this () is not callable using argument types () which seems a bit wrong? Thanks, Richard Webb
Dec 10 2009
On Thu, 10 Dec 2009 19:23:43 -0500, Richard Webb <webby beardmouse.org.uk> wrote:I just tried to build the Juno library with DMD 2.037, and got a bunch or errors like: juno\com\core.d(295): Error: function juno.com.core.GUID.opEquals type signature should be const bool(ref const(GUID)) not bool(GUID other) Which can be replicated with: //////////////////////////////// struct Foo { bool opEquals(Foo f) const { return true; } } void Bar() { Foo f; } //////////////////////////////// It built ok with DMD2 a few months ago. Is this an intentional change?It's due to this change: http://www.dsource.org/projects/dmd/changeset/260 The issue being fixed was this: http://d.puremagic.com/issues/show_bug.cgi?id=3433 I think it should be a bug, because your opEquals does not violate const, since you are making a copy of a Foo, and Foo contains no references. Please file a bug and reference 3433 and changeset 260. I think it should be allowed to have a signature like this: bool opEquals(T other) const inside T as long as T can be implicitly cast from const to mutable.Also, while looking at the problem i noticed that code like: //////////////////////////////// struct Foo { ~this() { } } void Bar() { const Foo f; } //////////////////////////////// Produces the error: Error: destructor Foo.~this () is not callable using argument types () which seems a bit wrong?Yeah, that's weird. Probably something to do with const. Probably should file another bug :) -Steve
Dec 11 2009
On Fri, 11 Dec 2009 07:13:35 -0500, Steven Schveighoffer <schveiguy yahoo.com> wrote:I think it should be a bugClarifying, I meant it is a bug in the compiler *not* in Juno :) -Steve
Dec 11 2009
Opened as 3606 and 3607. Thanks, Richard Webb
Dec 11 2009