From: Kriang Lerdsuwanakij Date: Thu, 18 Dec 2003 14:14:48 +0000 (+0000) Subject: re PR c++/13262 ("xxx is private within this context" when initializing a *self-conta... X-Git-Tag: releases/gcc-3.4.0~1602 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=bc5ada84727516c1617c604837fa9c58a4a689db;p=thirdparty%2Fgcc.git re PR c++/13262 ("xxx is private within this context" when initializing a *self-contained* template class) PR c++/13262 * pt.c (instantiate_decl): Wrap push_nested_class and pop_nested_class around cp_finish_decl call for static member variable. * g++.dg/template/access13.C: New test. From-SVN: r74780 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 8d9d9a34e6b5..178924389461 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2003-12-18 Kriang Lerdsuwanakij + + PR c++/13262 + * pt.c (instantiate_decl): Wrap push_nested_class and + pop_nested_class around cp_finish_decl call for static member + variable. + 2003-12-18 Giovanni Bajo PR c++/9154 diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 1a03bba6b89e..8445dcec53f5 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -11115,10 +11115,20 @@ instantiate_decl (tree d, int defer_ok) /* Mark D as instantiated so that recursive calls to instantiate_decl do not try to instantiate it again. */ DECL_TEMPLATE_INSTANTIATED (d) = 1; + /* This is done in analogous to `start_decl'. It is + required for correct access checking. */ + push_nested_class (DECL_CONTEXT (d)); cp_finish_decl (d, (!DECL_INITIALIZED_IN_CLASS_P (d) ? DECL_INITIAL (d) : NULL_TREE), NULL_TREE, 0); + /* Normally, pop_nested_class is called by cp_finish_decl + above. But when instantiate_decl is triggered during + instantiate_class_template processing, its DECL_CONTEXT + is still not completed yet, and pop_nested_class isn't + called. */ + if (!COMPLETE_TYPE_P (DECL_CONTEXT (d))) + pop_nested_class (); } } else if (TREE_CODE (d) == FUNCTION_DECL) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 33e5eb89ae62..009c8e9c6911 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2003-12-18 Kriang Lerdsuwanakij + + PR c++/13262 + * g++.dg/template/access13.C: New test. + 2003-12-18 Ulrich Weigand * gcc.dg/20031216-1.c: New test. diff --git a/gcc/testsuite/g++.dg/template/access13.C b/gcc/testsuite/g++.dg/template/access13.C new file mode 100644 index 000000000000..3a1442bb0e27 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/access13.C @@ -0,0 +1,16 @@ +// { dg-do compile } + +// Origin: Francesco Monica + +// PR c++/13262: Access checking during instantiation of static data +// member. + +template class Aclass { + private: + Aclass() {} + static Aclass instance; +}; + +template Aclass Aclass::instance; + +template class Aclass;