This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[C++ PATCH for 3.3] Fix regression PR10849 (specialization of nestedclass)


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.)


2003-05-26  Kriang Lerdsuwanakij  <>

	PR c++/10849
	* search.c (type_access_control): Don't check access when

2003-05-26  Kriang Lerdsuwanakij  <>

	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))
    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)
    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 <>
+ // 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>;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]