c++: TI_DEFERRED_ACCESS_CHECKS and dependent decls
authorPatrick Palka <ppalka@redhat.com>
Tue, 16 Jun 2020 12:51:34 +0000 (08:51 -0400)
committerPatrick Palka <ppalka@redhat.com>
Tue, 16 Jun 2020 12:51:34 +0000 (08:51 -0400)
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
gcc/cp/semantics.c

index 73f5935a4dc3530fd8a61d1ed8f671191692df33..efc69d5f81c43544c983282dbef625a1cd3ad09f 100644 (file)
@@ -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);
 
index a04b0aa1d9bfdd21be05bc0614638682caa5affd..2e65c277542e7dbbacb67528236e54b743dbc3e0 100644 (file)
@@ -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;