This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/52185] Const member function may change the object for which the function is called.
- From: "redi at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 09 Feb 2012 17:00:32 +0000
- Subject: [Bug c++/52185] Const member function may change the object for which the function is called.
- Auto-submitted: auto-generated
- References: <bug-52185-4@http.gcc.gnu.org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52185
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-02-09 17:00:32 UTC ---
G++ is correct.
In A::fun() 'this' is 'const A*' but you can still change A::a1 through a
reference.
Compare:
int* p;
struct A {
int a1;
A() : a1(-1) { }
int fun() const { return ++*p; }
};
int main()
{
A a;
p = &a.a1;
return a.fun();
}