This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[C++ PATCH] Fix PR13262 regression (static member init accesschecking)
- From: Kriang Lerdsuwanakij <lerdsuwa at users dot sourceforge dot net>
- To: <gcc-patches at gcc dot gnu dot org>
- Date: Mon, 15 Dec 2003 19:12:45 +0700 (ICT)
- Subject: [C++ PATCH] Fix PR13262 regression (static member init accesschecking)
- Reply-to: <lerdsuwa at users dot sourceforge dot net>
Hi
This patch fixes PR13262 which is marked as regression in 3.3 and 3.4
(only because we didn't do much access checking in 3.2). Inside
function instantiate_decl, we need to setup scope before calling
cp_finish_decl because it may call constructors while building
initialization code for this DECL, requiring access checking. Too bad
cp_finish_decl has some magic that pop the scope in most cases and
we have to pop it here for the remaining cases (they are commented
in the patch.
The patch below is for 3.4. Patch for 3.3 differs only in one aspect:
there is an extra argument for push_nested_class call. This will be
post in a separate message.
Tested on i686-pc-linux-gnu. Ok to commit to mainline and 3.3?
--Kriang
2003-12-15 Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
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-15 Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
PR c++/13262
* g++.dg/template/access13.C: New test.
diff -cprN gcc-main-save/gcc/cp/pt.c gcc-main-new/gcc/cp/pt.c
*** gcc-main-save/gcc/cp/pt.c Fri Dec 5 21:09:31 2003
--- gcc-main-new/gcc/cp/pt.c Fri Dec 12 22:17:50 2003
*************** instantiate_decl (tree d, int defer_ok)
*** 11115,11124 ****
--- 11115,11134 ----
/* 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 -cprN gcc-main-save/gcc/testsuite/g++.dg/template/access13.C gcc-main-new/gcc/testsuite/g++.dg/template/access13.C
*** gcc-main-save/gcc/testsuite/g++.dg/template/access13.C Thu Jan 1 07:00:00 1970
--- gcc-main-new/gcc/testsuite/g++.dg/template/access13.C Sun Dec 7 18:30:42 2003
***************
*** 0 ****
--- 1,16 ----
+ // { dg-do compile }
+
+ // Origin: Francesco Monica <fmonica@ce.unipr.it>
+
+ // PR c++/13262: Access checking during instantiation of static data
+ // member.
+
+ template <typename T> class Aclass {
+ private:
+ Aclass() {}
+ static Aclass instance;
+ };
+
+ template <typename T> Aclass<T> Aclass<T>::instance;
+
+ template class Aclass<int>;