In the following class template, the protected using declaration causes the inherited member to become publicly accessible. The code compiles, even though it shouldn't. template <typename T> struct B { protected: T v; }; template <typename T> struct D : B<T> { protected: using B<T>::v; }; int main() { D<int> d; d.v = 0; return 0; } $ g++ test.cpp The same code without templates gives the correct behaviour and doesn't compile. struct B { protected: int v; }; struct D : B { protected: using B::v; }; int main() { D d; d.v = 0; return 0; } $ g++ test.cpp test.cpp: In function 'int main()': test.cpp:4: error: 'int B::v' is protected test.cpp:14: error: within this context The preprocessed file from the template version is as follows: # 1 "test.cpp" # 1 "<built-in>" # 1 "<command line>" # 1 "test.cpp" template <typename T> struct B { protected: T v; }; template <typename T> struct D : B<T> { protected: using B<T>::v; }; int main() { D<int> d; d.v = 0; return 0; }
Confirmed, a regression from 4.0.4.
A regression hunt identified the following patch: http://gcc.gnu.org/viewcvs?view=rev&rev=100757 r100757 | nathan | 2005-06-08 11:49:23 +0000 (Wed, 08 Jun 2005)
Closing 4.1 branch.
Subject: Bug 29470 Author: jason Date: Fri Jan 16 22:36:11 2009 New Revision: 143445 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=143445 Log: PR c++/29470 * pt.c (tsubst_decl) [USING_DECL]: Propagate access flags. Added: trunk/gcc/testsuite/g++.dg/template/access20.C Modified: trunk/gcc/cp/ChangeLog trunk/gcc/cp/pt.c trunk/gcc/testsuite/ChangeLog trunk/gcc/testsuite/g++.dg/torture/pr34641.C
Fixed for 4.4, not fixing accepts-invalid on other branches.