This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/32410] New: Const functions in template don't give access errors with this until instantiated.
- From: "coppro at users dot sourceforge dot net" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 19 Jun 2007 22:38:25 -0000
- Subject: [Bug c++/32410] New: Const functions in template don't give access errors with this until instantiated.
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
If you create a const member function to a template class, it seems to be able
to change a non-mutable member of the function by using the this pointer. The
following illegal code compiles:
template <typename T>
class Class
{
unsigned int i;
public:
void foo () const
{
this->i++;
}
};
However, if Class<whatever>::foo is instantiated, then it gives an error for
changing the constant data member. However, if you remove the "this->" line,
the access errors occur even without an instantion. This is inconsistent
behavior. They should both cause errors at the same point.
--
Summary: Const functions in template don't give access errors
with this until instantiated.
Product: gcc
Version: 4.1.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: coppro at users dot sourceforge dot net
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32410