This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/53281] New: poor error message for calling a non-const method from a const object


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".


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]