digitalmars.D.bugs - [Issue 1730] New: const struct member func return invariant string can't assign to invariant string
- d-bugmail puremagic.com Dec 13 2007
- "Janice Caron" <caron800 googlemail.com> Dec 13 2007
- d-bugmail puremagic.com Dec 15 2007
- d-bugmail puremagic.com Nov 20 2009
- d-bugmail puremagic.com Mar 13 2010
http://d.puremagic.com/issues/show_bug.cgi?id=1730 Summary: const struct member func return invariant string can't assign to invariant string Product: D Version: 2.008 Platform: PC OS/Version: Windows Status: NEW Keywords: rejects-valid Severity: normal Priority: P2 Component: DMD AssignedTo: bugzilla digitalmars.com ReportedBy: davidl 126.com struct mystruct{ invariant(char)[] toChars() { return "asdf"; } } void func(in mystruct s) { invariant(char)[] k=s.toChars; } testconst.d(9): function testconst.mystruct.toChars () does not match parameter types () testconst.d(9): Error: s.toChars can only be called on a mutable object, not const(mystruct) --
Dec 13 2007
On 12/14/07, d-bugmail puremagic.com <d-bugmail puremagic.com> wrote:struct mystruct{ invariant(char)[] toChars() { return "asdf"; } } void func(in mystruct s) { invariant(char)[] k=s.toChars; }
That's correct behaviour, surely? Change the function definition to const invariant(char)[] toChars() { return "asdf"; } and the problem should go away. toChars() as written is incorrectly declared. It does not modify this, therefore it should be declared const. That said, I don't understant how s got to be const in the first place! Does "in" make things const?
Dec 13 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1730 davidl 126.com changed: What |Removed |Added ---------------------------------------------------------------------------- Severity|normal |minor Keywords|rejects-valid | Summary|const struct member func |error message enhance? |return invariant string | |can't assign to invariant | |string | ------- Comment #2 from davidl 126.com 2007-12-15 07:40 ------- But at least the first error message is confusing. --
Dec 15 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1730 --- Comment #3 from Stewart Gordon <smjg iname.com> 2009-11-20 11:10:48 PST --- Probably part of the same bug: ---------- class Class { void fn1() const { fn2(); } void fn2() {} } ---------- const_call.d(3): Error: function const_call.Class.fn2 () is not callable using argument types () const ---------- This may make sense at the internal level, as trying to convert the 'this' argument implicitly from const(Class) to Class. But as a user error message, it's confusing. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Nov 20 2009
http://d.puremagic.com/issues/show_bug.cgi?id=1730 Michal Spadlinski <gim913 gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |gim913 gmail.com --- Comment #4 from Michal Spadlinski <gim913 gmail.com> 2010-03-13 07:25:52 PST --- I has similar problem with: struct Foo { bool boo() { return false; } int foo () const { assert (boo); return 66; } } this message is totally misleading -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Mar 13 2010









"Janice Caron" <caron800 googlemail.com> 