This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/30331] a const member function can call a non_const member function without const_cast
- From: "gdr at integrable-solutions dot net" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 30 Dec 2006 11:21:00 -0000
- Subject: [Bug c++/30331] a const member function can call a non_const member function without const_cast
- References: <bug-30331-13838@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #2 from gdr at integrable-solutions dot net 2006-12-30 11:21 -------
Subject: Re: New: a const member function can call a non_const member
function without const_cast
"hongleij at 126 dot com" <gcc-bugzilla@gcc.gnu.org> writes:
| //const_test.cpp
| struct A
| {
| A(unsigned int n)
| {
| aa=n;
| }
| void const_fun() const
| {
| static_cast<A>(*this).fun(); //ok
yes, as mandated by C++ semantics -- the static_cast creates a
new object to which fun() is applied. That is OK.
| // fun(); //err
direct call to fun() is an error.
So, this PR does not report an error. It should be closed as "mistaken".
-- Gaby
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30331