This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/30331] New: a const member function can call a non_const member function without const_cast
- From: "hongleij at 126 dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 30 Dec 2006 07:58:14 -0000
- Subject: [Bug c++/30331] New: a const member function can call a non_const member function without const_cast
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
//const_test.cpp
struct A
{
A(unsigned int n)
{
aa=n;
}
void const_fun() const
{
static_cast<A>(*this).fun(); //ok
// fun(); //err
}
void fun()
{
}
unsigned int aa;
};
int main()
{
const A a(56);
a.const_fun();
}
// g++ const_test.cpp
// ./a.out
//we should forbid call non_const member function in a const member function
without an explicit const_cast ,isn't it?
--
Summary: a const member function can call a non_const member
function without const_cast
Product: gcc
Version: 4.1.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: hongleij at 126 dot com
GCC host triplet: all
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30331