digitalmars.D - const/invariant bug?
- Craig Black (17/17) Apr 02 2008 Unless I misunderstand something this shouldn't compile. But it compile...
- Walter Bright (1/1) Apr 02 2008 You're right, it shouldn't compile.
- Walter Bright (4/5) Apr 03 2008 That should work, but at the moment:
- Extrawurst (2/7) Apr 03 2008 Why do we need the suffix "const" anyway ? Isnt unambiguity a virtue ?
- Walter Bright (2/3) Apr 03 2008 Some people prefer it.
- Extrawurst (3/6) Apr 03 2008 Some people seem to prefer untransitive const too ;)
- Derek Parnell (7/11) Apr 03 2008 Does that principal also apply to 'alias' or 'maifest' or 'define' inste...
- Dave (23/27) Apr 05 2008 Since there has, understandably, been some confusion about what const re...
Unless I misunderstand something this shouldn't compile. But it compiles fine in DMD 2.012. Is this a bug? import std.stdio; class A { public: int x = 0; void setX(int nx) const { x = nx; } } void foo(const A a) { a.setX(1); } int main(char[][] args) { A a = new A; foo(a); writefln(a.x); return 0; }
Apr 02 2008
Craig Black wrote:void setX(int nx) const { x = nx; }That should work, but at the moment: const void setX(int nx) { x = nx; } does work.
Apr 03 2008
Walter Bright schrieb:Craig Black wrote:Why do we need the suffix "const" anyway ? Isnt unambiguity a virtue ?void setX(int nx) const { x = nx; }That should work, but at the moment: const void setX(int nx) { x = nx; } does work.
Apr 03 2008
Extrawurst wrote:Why do we need the suffix "const" anyway ? Isnt unambiguity a virtue ?Some people prefer it.
Apr 03 2008
Walter Bright schrieb:Extrawurst wrote:Some people seem to prefer untransitive const too ;) (i am not one of those, to pe clear on that)Why do we need the suffix "const" anyway ? Isnt unambiguity a virtue ?Some people prefer it.
Apr 03 2008
On Thu, 03 Apr 2008 11:33:10 -0700, Walter Bright wrote:Extrawurst wrote:Does that principal also apply to 'alias' or 'maifest' or 'define' instead of enum for manifest constants? -- Derek Parnell Melbourne, Australia skype: derek.j.parnellWhy do we need the suffix "const" anyway ? Isnt unambiguity a virtue ?Some people prefer it.
Apr 03 2008
"Walter Bright" <newshound1 digitalmars.com> wrote in message news:ft380r$13vn$1 digitalmars.com...Extrawurst wrote:Why do we need the suffix "const" anyway ? Isnt unambiguity a virtue ?Some people prefer it.const void setX(int nx) { x = nx; }Since there has, understandably, been some confusion about what const refers to with the prefixed form, why don't we get rid of the prefixed form altogether for 2.0? You could still allow: class C { const { int[] foo() { } // int[] foo() const { } double[] bar() { } // double[] bar() const { } } } because you have to do const(int[]) foo() to specify it for the return type anyhow, which is consistent between member and non-member functions. I doubt at this point it would break all that much code and the deprecated switch could serve in the interim. I really think this change would be worth it considering all of the confusion the prefix form will cause down the road, especially for C++ users. Thanks, - Dave
Apr 05 2008