Thread overview | ||||||
---|---|---|---|---|---|---|
|
December 11, 2009 [D2] const vs structs | ||||
---|---|---|---|---|
| ||||
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 |
December 11, 2009 Re: [D2] const vs structs | ||||
---|---|---|---|---|
| ||||
Posted in reply to Richard Webb | 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 |
December 11, 2009 Re: [D2] const vs structs | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | On Fri, 11 Dec 2009 07:13:35 -0500, Steven Schveighoffer <schveiguy@yahoo.com> wrote:
> I think it should be a bug
Clarifying, I meant it is a bug in the compiler *not* in Juno :)
-Steve
|
December 11, 2009 Re: [D2] const vs structs | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | Opened as 3606 and 3607. Thanks, Richard Webb |
Copyright © 1999-2021 by the D Language Foundation