Bug 13445 - [3.3 Regression] Template argument replacement "dereferences" a typedef
Summary: [3.3 Regression] Template argument replacement "dereferences" a typedef
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.3.2
: P2 critical
Target Milestone: 3.3.3
Assignee: Nathan Sidwell
Keywords: rejects-valid
Depends on:
Reported: 2003-12-19 14:54 UTC by brad.king
Modified: 2003-12-30 09:49 UTC (History)
2 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work:
Known to fail:
Last reconfirmed: 2003-12-19 15:39:19


Note You need to log in before you can comment on or make changes to this bug.
Description brad.king 2003-12-19 14:54:31 UTC
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 \
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
Comment 1 Andrew Pinski 2003-12-19 15:39:18 UTC
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).
Comment 2 Wolfgang Bangerth 2003-12-19 16:41:09 UTC
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. 
Comment 3 Wolfgang Bangerth 2003-12-19 16:41:41 UTC
Sorry, this has nothing to do with friendship, of course, and all 
with access control. 
Comment 4 brad.king 2003-12-19 19:45:53 UTC
I've discovered that applying this patch manually fixes the bug:


I am unable to confirm whether it introduces any other bugs when included in the
3.3 branch.
Comment 5 Andrew Pinski 2003-12-19 19:51:55 UTC
It does look like that is the patch fixes it.
Nathan could you backport this patch for 3.3.3:
        * pt.c (instantiate_class_template): Push to class's scope before
        tsubsting base.
        * g++.dg/template/scope2.C: New test.
        * g++.dg/template/error2.C: Correct dg-error
Comment 6 CVS Commits 2003-12-30 09:47:37 UTC
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:
	PR c++/13445
	* pt.c (instantiate_class_template): Push to class's scope before
	tsubsting base.
	PR c++/13445
	* g++.dg/template/scope2.C: New test.


Comment 7 Nathan Sidwell 2003-12-30 09:49:07 UTC
2003-12-30  Nathan Sidwell  <nathan@codesourcery.com>

	PR c++/13445
	* pt.c (instantiate_class_template): Push to class's scope before
	tsubsting base.