This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/53281] New: poor error message for calling a non-const method from a const object
- From: "rui.maciel at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 08 May 2012 13:25:07 +0000
- Subject: [Bug c++/53281] New: poor error message for calling a non-const method from a const object
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53281
Bug #: 53281
Summary: poor error message for calling a non-const method from
a const object
Classification: Unclassified
Product: gcc
Version: 4.6.3
Status: UNCONFIRMED
Severity: enhancement
Priority: P3
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: rui.maciel@gmail.com
Consider the following code:
<code>
class Foo {
void bar1() {}
void bar2(Foo const &foo) {
foo.bar1();
}
};
int main()
{
return 0;
}
</code>
When this code is compiled with g++, the following error message is shown:
<message>
main.c++: In member function âconst void Foo::bar2(const Foo&)â:
main.c++:4:26: error: passing âconst Fooâ as âthisâ argument of âconst void
Foo::bar1()â discards qualifiers [-fpermissive]
</message>
The error message is technically correct. Yet, it is too cryptic and a bit
unhelpful, to the point it may be considered that the point of this error
message is entirely missed.
As an alternative, it would be nice if g++ displayed an error message which
would actually be straight-forward and provided a clear description of the
problem at hand, such as "trying to call a non-const method from a const
object".