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.
This is correct as "*this" is dependent so the compiler cannot resolve that until instantation time so this is not a bug. >This is inconsistent behavior. Yes but i here is not depdendent. While this->i is.