From 28462a4496152c76babdb09806762880633191f5 Mon Sep 17 00:00:00 2001 From: Patrick Palka Date: Tue, 16 Jun 2020 08:51:34 -0400 Subject: [PATCH] c++: TI_DEFERRED_ACCESS_CHECKS and dependent decls This adds an assert to enforce_access to verify that we don't defer access checks of dependent decls -- we should instead be rechecking the access of such a decl after tsubst'ing into the user of the decl. gcc/cp/ChangeLog: * pt.c (perform_instantiation_time_access_checks): No need to tsubst into decl. * semantics.c (enforce_access): Verify that decl is not dependent. --- gcc/cp/pt.c | 4 ---- gcc/cp/semantics.c | 7 +++++++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 73f5935..efc69d5 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -11532,10 +11532,6 @@ perform_instantiation_time_access_checks (tree tmpl, tree targs) tree diag_decl = chk->diag_decl; tree type_scope = TREE_TYPE (chk->binfo); - if (uses_template_parms (decl) - || (TREE_CODE (decl) == FIELD_DECL - && uses_template_parms (DECL_CONTEXT (decl)))) - decl = tsubst_copy (decl, targs, tf_error, NULL_TREE); if (uses_template_parms (type_scope)) type_scope = tsubst (type_scope, targs, tf_error, NULL_TREE); diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index a04b0aa..2e65c27 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -294,6 +294,13 @@ enforce_access (tree basetype_path, tree decl, tree diag_decl, assume it'll be accessible at instantiation time. */ return true; + /* Access of a dependent decl should be rechecked after tsubst'ing + into the user of the decl, rather than explicitly deferring the + check here. */ + gcc_assert (!uses_template_parms (decl)); + if (TREE_CODE (decl) == FIELD_DECL) + gcc_assert (!uses_template_parms (DECL_CONTEXT (decl))); + /* Defer this access check until instantiation time. */ deferred_access_check access_check; access_check.binfo = basetype_path; -- 2.7.4