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++/17649] New: template protected member: no visibility in derived class


If a base class has a protected member, then a derived class method should have 
access to its member.  However, for template classes only, the derived class 
does not.  (interestingly, derived class members do appear to have access to 
the member in another derived class object - just not in the this object.)  
This is a regression from 3.3.4.

[marshals@itanic marshals]$ ~/slash342/usr/local/bin/g++ -v
Reading specs from /home/marshals/slash342/usr/local/lib/gcc/ia64-redhat-
linux/3.4.2/specs
Configured with: ../configure --prefix=/home/marshals/slash342/usr/local --
enable-languages=c,c++ --enable-shared --enable-threads=posix --disable-
checking --with-system-zlib --enable-__cxa_atexit --host=ia64-redhat-linux
Thread model: posix
gcc version 3.4.2
[marshals@itanic itanic]$ ~/slash342/usr/local/bin/g++ bug1.cpp
bug1.cpp: In copy constructor `tderiv<T_t>::tderiv(const tderiv<T_t>&)':
bug1.cpp:38: error: `_foo' undeclared (first use this function)
bug1.cpp:38: error: (Each undeclared identifier is reported only once for each 
function it appears in.)
[marshals@itanic itanic]$ cat bug1.cpp
// Base class with protected member.
class base
{
public:
        base ();
        base (const base &foo);
protected:
        int _foo;
};

// Derived class that sets base's protected member.
class deriv : public base
{
public:
        deriv (const deriv &foo) {
                int bar = foo._foo;
                _foo = bar;
        }
};

// Exactly as above, except as template classes.
template <class T_t>
class tbase
{
public:
        tbase ();
        tbase (const tbase<T_t> &foo);
protected:
        int _foo;
};

template <class T_t>
class tderiv : public tbase<T_t>
{
public:
        tderiv (const tderiv<T_t> &foo) {
                int bar = foo._foo;
                _foo = bar;
                // Line above results in:
// bug1.cpp: In copy constructor `tderiv<T_t>::tderiv(const tderiv<T_t>&)':
// bug1.cpp:38: error: `_foo' undeclared (first use this function)
// bug1.cpp:38: error: (Each undeclared identifier is reported only once for 
each function it appears in.)
        }
};

int main () {
        return 0;
}

-- 
           Summary: template protected member: no visibility in derived
                    class
           Product: gcc
           Version: 3.4.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: simon dot marshall at misys dot com
                CC: gcc-bugs at gcc dot gnu dot org
  GCC host triplet: ia64-redhat-linux


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17649


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