This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[C++ PATCH for 3.3] Fix regression PR10849 (specialization of nestedclass)
- From: Kriang Lerdsuwanakij <lerdsuwa at users dot sourceforge dot net>
- To: <gcc-patches at gcc dot gnu dot org>
- Date: Sun, 25 May 2003 00:59:26 +0700 (ICT)
- Subject: [C++ PATCH for 3.3] Fix regression PR10849 (specialization of nestedclass)
- Reply-to: <lerdsuwa at users dot sourceforge dot net>
Hi
This is a patch to fix PR10849, a regression on 3.3. It was
due to my change earlier (dated back to 2002-07-22) to add
access checking to TEMPLATE_DECL nodes. Before that, all
TEMPLATE_DECL nodes were ignored.
The parser in 3.3 have problem checking access in class head
of specialization, because current_class_type is not setup
in those cases. So the code like
template <> struct X::Y<int> {};
fails when 'Y' is private because we are trying to check
access from global scope rather than from the scope inside
'X'. Note that the main trunk already does the right thing
by not checking any access at all in the class head, and
therefore not affected by this bug.
I feel that fixing this by pushing/poping the scope properly
is not worth the trouble. Currently, the scope is not properly
poped in case of certain illegal codes. It will trigger the
'confused by earlier errors...' message. We already have a few
of those in the Bugzilla, fixing it will lead to additional
cases for the above message.
Simply disable appears a safer solution, which is proposed
in the appended patch. The code in main trunk is completely
different and doesn't require such workaround.
Tested on i686-pc-linux-gnu with no regressions. OK to
commit to 3.3 branch? (The testcase will be added to trunk
as well.)
--Kriang
2003-05-26 Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
PR c++/10849
* search.c (type_access_control): Don't check access when
processing_specialization.
2003-05-26 Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
PR c++/10849
* g++.dg/template/access10.C: New test.
diff -cprN gcc-33-save/gcc/cp/search.c gcc-33-new/gcc/cp/search.c
*** gcc-33-save/gcc/cp/search.c Thu May 22 19:19:30 2003
--- gcc-33-new/gcc/cp/search.c Sat May 24 19:03:32 2003
*************** type_access_control (type, val)
*** 1020,1026 ****
{
if (val == NULL_TREE
|| (TREE_CODE (val) != TEMPLATE_DECL && TREE_CODE (val) != TYPE_DECL)
! || ! DECL_CLASS_SCOPE_P (val))
return;
if (type_lookups == error_mark_node)
--- 1020,1027 ----
{
if (val == NULL_TREE
|| (TREE_CODE (val) != TEMPLATE_DECL && TREE_CODE (val) != TYPE_DECL)
! || ! DECL_CLASS_SCOPE_P (val)
! || processing_specialization)
return;
if (type_lookups == error_mark_node)
diff -cprN gcc-33-save/gcc/testsuite/g++.dg/template/access10.C gcc-33-new/gcc/testsuite/g++.dg/template/access10.C
*** gcc-33-save/gcc/testsuite/g++.dg/template/access10.C Thu Jan 1 07:00:00 1970
--- gcc-33-new/gcc/testsuite/g++.dg/template/access10.C Sat May 24 23:26:59 2003
***************
*** 0 ****
--- 1,16 ----
+ // { dg-do compile }
+
+ // Origin: Giovanni Bajo <giovannibajo@libero.it>
+
+ // PR c++/10849: Incorrect access checking on template specialization.
+
+ class X {
+ private:
+ template <typename T> struct Y;
+ };
+
+ template <> struct X::Y<int> {};
+
+ template <typename T> struct X::Y {};
+
+ template struct X::Y<int>;