Bug 32410 - Const functions in template don't give access errors with this until instantiated.
Summary: Const functions in template don't give access errors with this until instanti...
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.1.2
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-06-19 22:38 UTC by Sean Hunt
Modified: 2007-06-19 23:13 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sean Hunt 2007-06-19 22:38:25 UTC
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.
Comment 1 Andrew Pinski 2007-06-19 23:13:15 UTC
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.