This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C++ PATCH: Fix PR 264
- To: gcc-patches at gcc dot gnu dot org
- Subject: C++ PATCH: Fix PR 264
- From: Mark Mitchell <mark at codesourcery dot com>
- Date: Sat, 17 Feb 2001 16:33:26 -0800
- Organization: CodeSourcery, LLC
When users declared an explicit specialization, we did not correctly
duplicate the access control information from the template being
specialized.
Tested on i686-pc-linux-gnu, applied on the mainline.
--
Mark Mitchell mark@codesourcery.com
CodeSourcery, LLC http://www.codesourcery.com
2001-02-17 Mark Mitchell <mark@codesourcery.com>
* pt.c (check_explicit_specialization): Copy TREE_PRIVATE and
TREE_PROTECTED from the template being specialized.
Index: cp/pt.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/pt.c,v
retrieving revision 1.519
diff -c -p -r1.519 pt.c
*** pt.c 2001/02/16 07:57:50 1.519
--- pt.c 2001/02/17 23:43:22
*************** check_explicit_specialization (declarato
*** 1662,1667 ****
--- 1662,1672 ----
DECL is specializing. */
copy_default_args_to_explicit_spec (decl);
+ /* This specialization has the same protection as the
+ template it specializes. */
+ TREE_PRIVATE (decl) = TREE_PRIVATE (gen_tmpl);
+ TREE_PROTECTED (decl) = TREE_PROTECTED (gen_tmpl);
+
/* Mangle the function name appropriately. Note that we do
not mangle specializations of non-template member
functions of template classes, e.g. with
Index: testsuite/g++.old-deja/g++.other/access11.C
===================================================================
RCS file: access11.C
diff -N access11.C
*** /dev/null Tue May 5 13:32:27 1998
--- access11.C Sat Feb 17 15:43:24 2001
***************
*** 0 ****
--- 1,20 ----
+ // Build don't link:
+ // Origin: r.spatschek@fz-juelich.de
+ // Special g++ Options: -w
+
+ class A
+ {
+ private:
+ template <class T> void g(T t) {}
+ int i;
+ };
+
+ template <>
+ void A::g<int>(int t) { i = 1; } // ERROR - private
+
+ int main()
+ {
+ A a;
+
+ a.g<int>(0); // ERROR - private
+ }