* [C++ PATCH] Fix PR8389
@ 2002-11-08 1:01 Kriang Lerdsuwanakij
2002-11-08 11:12 ` Mark Mitchell
0 siblings, 1 reply; 2+ messages in thread
From: Kriang Lerdsuwanakij @ 2002-11-08 1:01 UTC (permalink / raw)
To: gcc-patches
Hi
The appended patch fixes PR 8389. This is a regression in the
main trunk caused by the enforcement of typename access checking
a couple months ago. There are a few missed cases. In particular,
inside "instantiate_template" and "get_mostly_instantiated_function_type"
functions, "current_class_type" is not properly set up when we are
tsubst'ing member functions. This is fixed by the patch.
The patch also simplify the function get_mostly_instantiated_function_type
a bit. The CONTEXTP and TPARMSP parameters are never used by the callers
so they are removed. Also, the tsubst call for the function context is
not required. It's the same for a fully instantiated DECL (with N levels
of template arguments), and a partially instantiated N-1 levels of
arguments.
Bootstrapped and tested on i686-pc-linux-gnu with no regressions.
OK to commit to main trunk?
--Kriang
2002-11-08 Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
PR c++/8389
* pt.c (instantiate_template): Push class scope for member
functions.
(get_mostly_instantiated_function_type): Likewise. Don't call
tsubst on context. Remove CONTEXTP and TPARMSP parameters.
* cp-tree.h (get_mostly_instantiated_function_type): Adjust.
* mangle.c (write_encoding, write_unqualified_name): Adjust.
2002-11-08 Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
PR c++/8389
* g++.dg/template/access6.C: New test.
diff -cprN gcc-main-save/gcc/cp/cp-tree.h gcc-main-new/gcc/cp/cp-tree.h
*** gcc-main-save/gcc/cp/cp-tree.h Wed Oct 30 22:49:01 2002
--- gcc-main-new/gcc/cp/cp-tree.h Fri Nov 8 11:39:15 2002
*************** extern void print_candidates
*** 4010,4016 ****
extern int instantiate_pending_templates PARAMS ((void));
extern tree tsubst_default_argument PARAMS ((tree, tree, tree));
extern tree most_general_template PARAMS ((tree));
! extern tree get_mostly_instantiated_function_type PARAMS ((tree, tree *, tree *));
extern int problematic_instantiation_changed PARAMS ((void));
extern void record_last_problematic_instantiation PARAMS ((void));
extern tree current_instantiation PARAMS ((void));
--- 4010,4016 ----
extern int instantiate_pending_templates PARAMS ((void));
extern tree tsubst_default_argument PARAMS ((tree, tree, tree));
extern tree most_general_template PARAMS ((tree));
! extern tree get_mostly_instantiated_function_type PARAMS ((tree));
extern int problematic_instantiation_changed PARAMS ((void));
extern void record_last_problematic_instantiation PARAMS ((void));
extern tree current_instantiation PARAMS ((void));
diff -cprN gcc-main-save/gcc/cp/mangle.c gcc-main-new/gcc/cp/mangle.c
*** gcc-main-save/gcc/cp/mangle.c Fri Oct 18 22:29:12 2002
--- gcc-main-new/gcc/cp/mangle.c Fri Nov 8 11:39:03 2002
*************** write_encoding (decl)
*** 656,662 ****
tree fn_type;
if (decl_is_template_id (decl, NULL))
! fn_type = get_mostly_instantiated_function_type (decl, NULL, NULL);
else
fn_type = TREE_TYPE (decl);
--- 656,662 ----
tree fn_type;
if (decl_is_template_id (decl, NULL))
! fn_type = get_mostly_instantiated_function_type (decl);
else
fn_type = TREE_TYPE (decl);
*************** write_unqualified_name (decl)
*** 1011,1018 ****
tree type;
if (decl_is_template_id (decl, NULL))
{
! tree fn_type = get_mostly_instantiated_function_type (decl, NULL,
! NULL);
type = TREE_TYPE (fn_type);
}
else
--- 1011,1017 ----
tree type;
if (decl_is_template_id (decl, NULL))
{
! tree fn_type = get_mostly_instantiated_function_type (decl);
type = TREE_TYPE (fn_type);
}
else
diff -cprN gcc-main-save/gcc/cp/pt.c gcc-main-new/gcc/cp/pt.c
*** gcc-main-save/gcc/cp/pt.c Wed Oct 30 22:49:01 2002
--- gcc-main-new/gcc/cp/pt.c Fri Nov 8 15:48:35 2002
*************** instantiate_template (tmpl, targ_ptr)
*** 7756,7764 ****
--- 7756,7774 ----
}
}
+ /* Make sure that we can see identifiers, and compute access
+ correctly. */
+ if (DECL_CLASS_SCOPE_P (gen_tmpl))
+ pushclass (tsubst (DECL_CONTEXT (gen_tmpl), targ_ptr, tf_error,
+ gen_tmpl), 1);
+
/* substitute template parameters */
fndecl = tsubst (DECL_TEMPLATE_RESULT (gen_tmpl),
targ_ptr, tf_error, gen_tmpl);
+
+ if (DECL_CLASS_SCOPE_P (gen_tmpl))
+ popclass ();
+
/* The DECL_TI_TEMPLATE should always be the immediate parent
template, not the most general template. */
DECL_TI_TEMPLATE (fndecl) = tmpl;
*************** tsubst_enum (tag, newtag, args)
*** 10384,10401 ****
/* DECL is a FUNCTION_DECL that is a template specialization. Return
its type -- but without substituting the innermost set of template
arguments. So, innermost set of template parameters will appear in
! the type. If CONTEXTP is non-NULL, then the partially substituted
! DECL_CONTEXT (if any) will also be filled in. Similarly, TPARMSP
! will be filled in with the substituted template parameters, if it
! is non-NULL. */
tree
! get_mostly_instantiated_function_type (decl, contextp, tparmsp)
tree decl;
- tree *contextp;
- tree *tparmsp;
{
- tree context = NULL_TREE;
tree fn_type;
tree tmpl;
tree targs;
--- 10394,10405 ----
/* DECL is a FUNCTION_DECL that is a template specialization. Return
its type -- but without substituting the innermost set of template
arguments. So, innermost set of template parameters will appear in
! the type. */
tree
! get_mostly_instantiated_function_type (decl)
tree decl;
{
tree fn_type;
tree tmpl;
tree targs;
*************** get_mostly_instantiated_function_type (d
*** 10412,10419 ****
my_friendly_assert (parm_depth == TMPL_ARGS_DEPTH (targs), 0);
fn_type = TREE_TYPE (tmpl);
- if (DECL_STATIC_FUNCTION_P (decl))
- context = DECL_CONTEXT (decl);
if (parm_depth == 1)
/* No substitution is necessary. */
--- 10416,10421 ----
*************** get_mostly_instantiated_function_type (d
*** 10433,10443 ****
TMPL_ARGS_DEPTH (targs),
make_tree_vec (DECL_NTPARMS (tmpl)));
/* Now, do the (partial) substitution to figure out the
appropriate function type. */
fn_type = tsubst (fn_type, partial_args, tf_error, NULL_TREE);
- if (DECL_STATIC_FUNCTION_P (decl))
- context = tsubst (context, partial_args, tf_error, NULL_TREE);
/* Substitute into the template parameters to obtain the real
innermost set of parameters. This step is important if the
--- 10435,10451 ----
TMPL_ARGS_DEPTH (targs),
make_tree_vec (DECL_NTPARMS (tmpl)));
+ /* Make sure that we can see identifiers, and compute access
+ correctly. We can just use the context of DECL for the
+ partial substitution here. It depends only on outer template
+ parameters, regardless of whether the innermost level is
+ specialized or not. */
+ if (DECL_CLASS_SCOPE_P (decl))
+ pushclass (DECL_CONTEXT (decl), 1);
+
/* Now, do the (partial) substitution to figure out the
appropriate function type. */
fn_type = tsubst (fn_type, partial_args, tf_error, NULL_TREE);
/* Substitute into the template parameters to obtain the real
innermost set of parameters. This step is important if the
*************** get_mostly_instantiated_function_type (d
*** 10445,10456 ****
parameters whose types depend on outer template parameters. */
TREE_VEC_LENGTH (partial_args)--;
tparms = tsubst_template_parms (tparms, partial_args, tf_error);
- }
! if (contextp)
! *contextp = context;
! if (tparmsp)
! *tparmsp = tparms;
return fn_type;
}
--- 10453,10462 ----
parameters whose types depend on outer template parameters. */
TREE_VEC_LENGTH (partial_args)--;
tparms = tsubst_template_parms (tparms, partial_args, tf_error);
! if (DECL_CLASS_SCOPE_P (decl))
! popclass ();
! }
return fn_type;
}
diff -cprN gcc-main-save/gcc/testsuite/g++.dg/template/access6.C gcc-main-new/gcc/testsuite/g++.dg/template/access6.C
*** gcc-main-save/gcc/testsuite/g++.dg/template/access6.C Thu Jan 1 07:00:00 1970
--- gcc-main-new/gcc/testsuite/g++.dg/template/access6.C Thu Nov 7 22:37:11 2002
***************
*** 0 ****
--- 1,17 ----
+ // { dg-do compile }
+ // Origin: Detlef Vollmann <dv@vollmann.ch>
+
+ // PR c++/8389
+ // Access control ICE for typename during instantiation and name mangling
+
+ template <class> class Base {
+ protected:
+ typedef int Type;
+ };
+
+ template <class T> struct Derived : public Base<T> {
+ typedef typename Base<T>::Type Type;
+ template <class Arg> void f(Type = Type()) {};
+ };
+
+ template void Derived<char>::f<int> (Type);
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [C++ PATCH] Fix PR8389
2002-11-08 1:01 [C++ PATCH] Fix PR8389 Kriang Lerdsuwanakij
@ 2002-11-08 11:12 ` Mark Mitchell
0 siblings, 0 replies; 2+ messages in thread
From: Mark Mitchell @ 2002-11-08 11:12 UTC (permalink / raw)
To: lerdsuwa, gcc-patches
--On Friday, November 08, 2002 04:04:48 PM +0700 Kriang Lerdsuwanakij
<lerdsuwa@users.sourceforge.net> wrote:
> Hi
>
> The appended patch fixes PR 8389. This is a regression in the
> main trunk caused by the enforcement of typename access checking
> a couple months ago. There are a few missed cases. In particular,
> inside "instantiate_template" and "get_mostly_instantiated_function_type"
> functions, "current_class_type" is not properly set up when we are
> tsubst'ing member functions. This is fixed by the patch.
OK; thanks.
--
Mark Mitchell mark@codesourcery.com
CodeSourcery, LLC http://www.codesourcery.com
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2002-11-08 19:12 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-11-08 1:01 [C++ PATCH] Fix PR8389 Kriang Lerdsuwanakij
2002-11-08 11:12 ` Mark Mitchell
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).