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++/12970] New: Strange class member access rules


This simple C++ program gives the following error which seems strange to me. GCC
3.3.1 compiles it fine.

$ g++ -W -Wall -o test test.cxx
test.cxx: In member function `void B<T>::foo(int)':
test.cxx:14: error: `x' undeclared (first use this function)
test.cxx:14: error: (Each undeclared identifier is reported only once for each f
unction it appears in.)

----8<----------
template <typename T>
class A
{
protected:
  int x;
};

template <typename T>
class B : public A<T>
{
public:
  void foo (int _x)
  {
    x = _x;
  }
};

int main ()
{
  B<int> b;
  b.foo(1);
  return 0;
}
----8<----------

GCC is:
Reading specs from /usr/local/lib/gcc/i686-pc-cygwin/3.4/specs
Configured with: ../srcdir/configure --enable-languages=c,c++ --enable-threads=p
osix --enable-version-specific-runtime-libs --enable-dwarf2 --with-cpu=athlon --
with-arch=athlon --without-included-gettext
Thread model: posix
gcc version 3.4 20031108 (experimental)

-- 
           Summary: Strange class member access rules
           Product: gcc
           Version: 3.4
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: v dot haisman at sh dot cvut dot cz
                CC: gcc-bugs at gcc dot gnu dot org,v dot haisman at sh dot
                    cvut dot cz
 GCC build triplet: i686-pc-cygwin
  GCC host triplet: i686-pc-cygwin
GCC target triplet: i686-pc-cygwin


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


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