This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[C++ PATCH, committed] Fix a scope problem in my previous patch
- From: Kriang Lerdsuwanakij <lerdsuwa at users dot sourceforge dot net>
- To: <gcc-patches at gcc dot gnu dot org>
- Date: Thu, 9 Jan 2003 21:02:13 +0700 (ICT)
- Subject: [C++ PATCH, committed] Fix a scope problem in my previous patch
- Reply-to: <lerdsuwa at users dot sourceforge dot net>
Hi
My previous patch overlook one case. When we are setting
'current_function_decl' and this function is in namespace scope,
the 'current_class_type' is not clear. So access checking code
view this function as a member of 'current_class_type' which is
not true. Also we will have to set 'current_function_decl'
after the 'push_to_top_level' function call. I commit this
as the changes only touch my previous code and it looks
straightforward. Patch tested on i686-pc-linux-gnu with
no regressions.
--Kriang
2003-01-09 Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
* pt.c (push_access_scope_real): Call push_to_top_level for
function in namespace scope.
(pop_access_scope): Call pop_from_top_level for function in
namespace scope.
2003-01-09 Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
* g++.dg/template/friend14.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 Thu Jan 9 19:16:01 2003
--- gcc-main-new/gcc/cp/pt.c Thu Jan 9 18:47:08 2003
*************** push_access_scope_real (t, args, context
*** 209,224 ****
if (spec)
t = spec;
}
-
- saved_access_scope = tree_cons
- (NULL_TREE, current_function_decl, saved_access_scope);
- current_function_decl = t;
}
if (!context)
context = DECL_CONTEXT (t);
if (context && TYPE_P (context))
push_nested_class (context, 2);
}
/* Like push_access_scope_real, but always uses DECL_CONTEXT. */
--- 209,229 ----
if (spec)
t = spec;
}
}
if (!context)
context = DECL_CONTEXT (t);
if (context && TYPE_P (context))
push_nested_class (context, 2);
+ else
+ push_to_top_level ();
+
+ if (TREE_CODE (t) == FUNCTION_DECL || DECL_FUNCTION_TEMPLATE_P (t))
+ {
+ saved_access_scope = tree_cons
+ (NULL_TREE, current_function_decl, saved_access_scope);
+ current_function_decl = t;
+ }
}
/* Like push_access_scope_real, but always uses DECL_CONTEXT. */
*************** void
*** 237,250 ****
pop_access_scope (t)
tree t;
{
- if (DECL_CLASS_SCOPE_P (t))
- pop_nested_class ();
-
if (TREE_CODE (t) == FUNCTION_DECL || DECL_FUNCTION_TEMPLATE_P (t))
{
current_function_decl = TREE_VALUE (saved_access_scope);
saved_access_scope = TREE_CHAIN (saved_access_scope);
}
}
/* Do any processing required when DECL (a member template
--- 242,257 ----
pop_access_scope (t)
tree t;
{
if (TREE_CODE (t) == FUNCTION_DECL || DECL_FUNCTION_TEMPLATE_P (t))
{
current_function_decl = TREE_VALUE (saved_access_scope);
saved_access_scope = TREE_CHAIN (saved_access_scope);
}
+
+ if (DECL_CLASS_SCOPE_P (t))
+ pop_nested_class ();
+ else
+ pop_from_top_level ();
}
/* Do any processing required when DECL (a member template
diff -cprN gcc-main-save/gcc/testsuite/g++.dg/template/friend14.C gcc-main-new/gcc/testsuite/g++.dg/template/friend14.C
*** gcc-main-save/gcc/testsuite/g++.dg/template/friend14.C Thu Jan 1 07:00:00 1970
--- gcc-main-new/gcc/testsuite/g++.dg/template/friend14.C Thu Jan 9 20:30:36 2003
***************
*** 0 ****
--- 1,20 ----
+ // { dg-do compile }
+
+ // Origin: Wolfgang Bangerth <bangerth@ticam.utexas.edu>
+
+ // Perform access checking to parameter and return type of
+ // function template correctly when the template is friend.
+
+ template <class T> class O {
+ struct I { I (int); };
+
+ template <class T_>
+ friend typename O<T_>::I f ();
+ };
+
+ template <class T_>
+ typename O<T_>::I f () { return 1; }
+
+ struct X {
+ void g() { f<int>(); }
+ };