From 0f399e5f9b8b238932eeaba618f6baefd7bdd36c Mon Sep 17 00:00:00 2001 From: Kriang Lerdsuwanakij Date: Thu, 9 Jan 2003 13:55:46 +0000 Subject: [PATCH] pt.c (push_access_scope_real): Call push_to_top_level for function in namespace scope. * 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. * g++.dg/template/friend14.C: New test. From-SVN: r61114 --- gcc/cp/ChangeLog | 7 +++++++ gcc/cp/pt.c | 21 ++++++++++++++------- gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/g++.dg/template/friend14.C | 20 ++++++++++++++++++++ 4 files changed, 45 insertions(+), 7 deletions(-) create mode 100644 gcc/testsuite/g++.dg/template/friend14.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 17626a93f46..cb9c6124ac4 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2003-01-09 Kriang Lerdsuwanakij + + * 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 Jakub Jelinek * decl.c (start_decl): Don't set DECL_COMMON for __thread variables. diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index b63443b174b..7802e25b573 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -209,16 +209,21 @@ push_access_scope_real (t, args, context) 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); + 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. */ @@ -237,14 +242,16 @@ void 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); } + + if (DECL_CLASS_SCOPE_P (t)) + pop_nested_class (); + else + pop_from_top_level (); } /* Do any processing required when DECL (a member template diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 413a12ecad5..8168b989ade 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2003-01-09 Kriang Lerdsuwanakij + + * g++.dg/template/friend14.C: New test. + 2003-01-09 Eric Botcazou * gcc.dg/old-style-asm-1.c: New test. diff --git a/gcc/testsuite/g++.dg/template/friend14.C b/gcc/testsuite/g++.dg/template/friend14.C new file mode 100644 index 00000000000..6e07b98932a --- /dev/null +++ b/gcc/testsuite/g++.dg/template/friend14.C @@ -0,0 +1,20 @@ +// { dg-do compile } + +// Origin: Wolfgang Bangerth + +// Perform access checking to parameter and return type of +// function template correctly when the template is friend. + +template class O { + struct I { I (int); }; + + template + friend typename O::I f (); +}; + +template +typename O::I f () { return 1; } + +struct X { + void g() { f(); } +}; -- 2.30.2