Bug 12970 - Strange class member access rules
Summary: Strange class member access rules
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.4.0
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
: 14376 15111 15372 15552 16067 16577 16709 22588 23735 23755 23908 23976 24960 25783 25827 25846 (view as bug list)
Depends on:
Blocks:
 
Reported: 2003-11-08 22:34 UTC by Václav Haisman
Modified: 2006-01-18 16:06 UTC (History)
18 users (show)

See Also:
Host: i686-pc-cygwin
Target: i686-pc-cygwin
Build: i686-pc-cygwin
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 Václav Haisman 2003-11-08 22:34:14 UTC
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)
Comment 1 Andrew Pinski 2003-11-08 22:37:22 UTC
Can you read <http://gcc.gnu.org/gcc-3.4/changes.html>, GCC is correct to reject this code.
Comment 2 Wolfgang Bangerth 2003-11-10 14:56:23 UTC
There's also a longer section in the non-bugs part of the manual
that explains what exactly is going on here.

W.
Comment 3 Andrew Pinski 2006-01-13 15:41:27 UTC
*** Bug 25783 has been marked as a duplicate of this bug. ***
Comment 4 Andrew Pinski 2006-01-13 15:41:53 UTC
*** Bug 24960 has been marked as a duplicate of this bug. ***
Comment 5 Andrew Pinski 2006-01-13 15:42:23 UTC
*** Bug 23976 has been marked as a duplicate of this bug. ***
Comment 6 Andrew Pinski 2006-01-13 15:43:37 UTC
*** Bug 23908 has been marked as a duplicate of this bug. ***
Comment 7 Andrew Pinski 2006-01-13 15:44:07 UTC
*** Bug 23755 has been marked as a duplicate of this bug. ***
Comment 8 Andrew Pinski 2006-01-13 15:44:34 UTC
*** Bug 23735 has been marked as a duplicate of this bug. ***
Comment 9 Andrew Pinski 2006-01-13 15:45:13 UTC
*** Bug 22588 has been marked as a duplicate of this bug. ***
Comment 10 Andrew Pinski 2006-01-13 15:45:47 UTC
*** Bug 16709 has been marked as a duplicate of this bug. ***
Comment 11 Andrew Pinski 2006-01-13 15:46:14 UTC
*** Bug 16577 has been marked as a duplicate of this bug. ***
Comment 12 Andrew Pinski 2006-01-13 15:46:47 UTC
*** Bug 16067 has been marked as a duplicate of this bug. ***
Comment 13 Andrew Pinski 2006-01-13 15:47:25 UTC
*** Bug 15372 has been marked as a duplicate of this bug. ***
Comment 14 Andrew Pinski 2006-01-13 15:47:51 UTC
*** Bug 15111 has been marked as a duplicate of this bug. ***
Comment 15 Andrew Pinski 2006-01-13 15:48:16 UTC
*** Bug 14376 has been marked as a duplicate of this bug. ***
Comment 16 Andrew Pinski 2006-01-13 15:50:36 UTC
*** Bug 15552 has been marked as a duplicate of this bug. ***
Comment 17 Andrew Pinski 2006-01-17 21:02:09 UTC
*** Bug 25827 has been marked as a duplicate of this bug. ***
Comment 18 Andrew Pinski 2006-01-18 16:06:34 UTC
*** Bug 25846 has been marked as a duplicate of this bug. ***