This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[C++ PATCH] Fix PR4802, 5387
- From: Kriang Lerdsuwanakij <lerdsuwa at users dot sourceforge dot net>
- To: gcc-patches at gcc dot gnu dot org
- Date: Mon, 27 May 2002 00:00:41 +0700
- Subject: [C++ PATCH] Fix PR4802, 5387
- Reply-to: lerdsuwa at users dot sourceforge dot net
Hi
This patch fixes PR4802 and PR5387 (not a regression). With the patch
type access is now enforced for typename types while previously they are
all treated as public.
Bootstrapped and tested with no regressions. OK to commit to the main
trunk?
--Kriang
2002-05-26 Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
PR c++/4802, c++/5387
* decl.c (make_typename_type): Use enforce_access.
diff -cprN gcc-main-save/gcc/cp/decl.c gcc-main-new/gcc/cp/decl.c
*** gcc-main-save/gcc/cp/decl.c Thu May 16 20:34:06 2002
--- gcc-main-new/gcc/cp/decl.c Sun May 26 22:43:58 2002
*************** make_typename_type (context, name, compl
*** 5735,5740 ****
--- 5735,5743 ----
return error_mark_node;
}
+ if (!enforce_access (context, tmpl))
+ return error_mark_node;
+
return lookup_template_class (tmpl,
TREE_OPERAND (fullname, 1),
NULL_TREE, context,
*************** make_typename_type (context, name, compl
*** 5755,5760 ****
--- 5758,5766 ----
t = lookup_field (context, name, 0, 1);
if (t)
{
+ if (!enforce_access (context, t))
+ return error_mark_node;
+
if (DECL_ARTIFICIAL (t) || !(complain & tf_keep_type_decl))
t = TREE_TYPE (t);
if (IMPLICIT_TYPENAME_P (t))
diff -cprN gcc-main-save/gcc/testsuite/g++.dg/template/access2.C gcc-main-new/gcc/testsuite/g++.dg/template/access2.C
*** gcc-main-save/gcc/testsuite/g++.dg/template/access2.C Thu Jan 1 07:00:00 1970
--- gcc-main-new/gcc/testsuite/g++.dg/template/access2.C Sun May 26 23:01:55 2002
***************
*** 0 ****
--- 1,20 ----
+ // { dg-do compile }
+
+ // PR c++/5387
+ // Enforcing access of typename type.
+
+ template <class T> struct A {
+ typename T::X x; // { dg-error "this context" }
+ int f() { return T::i; } // { dg-error "this context" }
+ };
+
+ class B {
+ typedef int X; // { dg-error "private" }
+ static int i; // { dg-error "private" }
+ };
+
+ int main()
+ {
+ A<B> ab; // { dg-error "instantiated" }
+ ab.f(); // { dg-error "instantiated" }
+ }
diff -cprN gcc-main-save/gcc/testsuite/g++.dg/template/access3.C gcc-main-new/gcc/testsuite/g++.dg/template/access3.C
*** gcc-main-save/gcc/testsuite/g++.dg/template/access3.C Thu Jan 1 07:00:00 1970
--- gcc-main-new/gcc/testsuite/g++.dg/template/access3.C Sun May 26 23:05:30 2002
***************
*** 0 ****
--- 1,17 ----
+ // { dg-do compile }
+
+ // PR c++/5387
+ // Enforcing access of typename type.
+
+ template <class T> struct A {
+ typename T::X<int> x; // { dg-error "this context" }
+ };
+
+ class B {
+ template <class T> class X {}; // { dg-error "private" }
+ };
+
+ int main()
+ {
+ A<B> ab; // { dg-error "instantiated" }
+ }