This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/32410] New: Const functions in template don't give access errors with this until instantiated.


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]