Bug 4497 – inexpressive error message for const object method
Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
All
Creation time
2010-07-23T18:16:00Z
Last change time
2012-12-23T13:45:34Z
Keywords
diagnostic
Assigned to
nobody
Creator
hoganmeier
Comments
Comment #0 by hoganmeier — 2010-07-23T18:16:17Z
class Foo
{
void getX()
{}
}
const Foo f;
void main()
{
f.getX();
}
Error: function constobj.Foo.getX () is not callable using argument types () const
This error message could be more expressive to show that getX must be marked as const to make it work.
Comment #1 by hoganmeier — 2010-07-24T04:39:33Z
Note that this is also true for objects passed to a function as "const Class object"
Comment #2 by schveiguy — 2010-07-26T06:20:03Z
I think the message is actually accurate. I'll split out the relevant parts:
testbug.d(11): Error: function
testbug.Foo.getX () is not callable using argument types
() const
What's happening is, the hidden this parameter is passed as const since the object is const, but getX doesn't accept a const Foo.
It's the same as if you had a function like this:
void foo(Foo x)
foo(f);
Since f is const, and foo(Foo) must accept a mutable foo.
However, most people see the "const" applying to the function, which is a common misconception.
I think a better error message might look like this:
Error: function constobj.Foo.getX () cannot be called using a const Foo.
Comment #3 by hoganmeier — 2010-08-03T06:01:11Z
I'm pretty sure I also had similar errors without the indicating "const" at the end of the message.
Comment #4 by andrej.mitrovich — 2012-12-23T13:45:34Z
*** This issue has been marked as a duplicate of issue 1730 ***