Every version of gcc 3.3.2 I've tested has the bug. I built a copy by downloading sources from ftp.gnu.org to be sure no distribution-specific patches were to blame: ../gcc-3.3.2/configure \ --prefix=/home/kingb/Temp/gcc-3.3.2-install \ --enable-languages=c,c++ make bootstrap make install "g++ --version" reports "g++ (GCC) 3.3.2" The following code reproduces the problem. It is expected to compile without error: template <class T> class NestedBase {}; template <class T> class Base { protected: typedef int Protected; }; template <class T> struct Derived: public Base<T> { typedef typename Base<T>::Protected Public; class Nested: public NestedBase<Public> {}; }; template class Derived<int>::Nested; Compiling the source with "./g++ -c bug.cxx" produces this error: bug.cxx: In instantiation of `Derived<int>::Nested': bug.cxx:8: instantiated from here bug.cxx:2: error: `typedef int Base<int>::Protected' is protected bug.cxx:8: error: within this context We see that the "Public" typedef is "dereferenced" while instantiating the template member class "Nested", which produces the access violation. Compiling the same source with g++ 3.2.3 or any earlier GCC version produces no error.
Broken: Search converges between 2002-07-14-trunk (#81) and 2002-07-21-trunk (#82). Fixed on the mainline: Search converges between 2003-08-17-trunk (#375) and 2003-08-18- trunk (#376). Confirmed.
Yup, this is bogus. It works on mainline, though. Kriang, you are the friendship expert, any chance to get this fixed on the branch? It is a regression with respect to 3.2.x. W.
Sorry, this has nothing to do with friendship, of course, and all with access control. W.
I've discovered that applying this patch manually fixes the bug: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/pt.c.diff?r1=1.758&r2=1.759 I am unable to confirm whether it introduces any other bugs when included in the 3.3 branch.
It does look like that is the patch fixes it. Nathan could you backport this patch for 3.3.3: cp: * pt.c (instantiate_class_template): Push to class's scope before tsubsting base. testsuite: * g++.dg/template/scope2.C: New test. * g++.dg/template/error2.C: Correct dg-error
Subject: Bug 13445 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-3_3-branch Changes by: nathan@gcc.gnu.org 2003-12-30 09:47:32 Modified files: gcc/cp : ChangeLog pt.c gcc/testsuite : ChangeLog Added files: gcc/testsuite/g++.dg/template: scope2.C Log message: cp: PR c++/13445 * pt.c (instantiate_class_template): Push to class's scope before tsubsting base. testsuite: PR c++/13445 * g++.dg/template/scope2.C: New test. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.3076.2.231&r2=1.3076.2.232 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/pt.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.635.2.39&r2=1.635.2.40 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.2261.2.347&r2=1.2261.2.348 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/scope2.C.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=NONE&r2=1.1.24.1
2003-12-30 Nathan Sidwell <nathan@codesourcery.com> PR c++/13445 * pt.c (instantiate_class_template): Push to class's scope before tsubsting base.