aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/decl2.cc
diff options
context:
space:
mode:
authorPatrick Palka <ppalka@redhat.com>2023-12-21 13:53:43 -0500
committerPatrick Palka <ppalka@redhat.com>2023-12-21 13:53:43 -0500
commit7226f825db049517b64442a40a6387513febb8f9 (patch)
tree0a8a02e95fe994c8c707d95695e4aaeb999d0a4e /gcc/cp/decl2.cc
parent135bb9e37167ef70501a888bd3db195b11b37ae3 (diff)
downloadgcc-7226f825db049517b64442a40a6387513febb8f9.zip
gcc-7226f825db049517b64442a40a6387513febb8f9.tar.gz
gcc-7226f825db049517b64442a40a6387513febb8f9.tar.bz2
c++: visibility wrt template and ptrmem targs [PR70413]
When constraining the visibility of an instantiation, we weren't properly considering the visibility of PTRMEM_CST and TEMPLATE_DECL template arguments. This patch fixes this. It turns out we don't maintain the relevant visibility flags for alias templates (e.g. TREE_PUBLIC is never set), so continue to ignore alias template template arguments for now. PR c++/70413 PR c++/107906 gcc/cp/ChangeLog: * decl2.cc (min_vis_expr_r): Handle PTRMEM_CST and TEMPLATE_DECL other than those for alias templates. gcc/testsuite/ChangeLog: * g++.dg/template/linkage2.C: New test. * g++.dg/template/linkage3.C: New test. * g++.dg/template/linkage4.C: New test. * g++.dg/template/linkage4a.C: New test.
Diffstat (limited to 'gcc/cp/decl2.cc')
-rw-r--r--gcc/cp/decl2.cc22
1 files changed, 18 insertions, 4 deletions
diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc
index 0850d3f..4777ceb 100644
--- a/gcc/cp/decl2.cc
+++ b/gcc/cp/decl2.cc
@@ -2655,7 +2655,10 @@ min_vis_expr_r (tree *tp, int */*walk_subtrees*/, void *data)
int *vis_p = (int *)data;
int tpvis = VISIBILITY_DEFAULT;
- switch (TREE_CODE (*tp))
+ tree t = *tp;
+ if (TREE_CODE (t) == PTRMEM_CST)
+ t = PTRMEM_CST_MEMBER (t);
+ switch (TREE_CODE (t))
{
case CAST_EXPR:
case IMPLICIT_CONV_EXPR:
@@ -2666,15 +2669,26 @@ min_vis_expr_r (tree *tp, int */*walk_subtrees*/, void *data)
case NEW_EXPR:
case CONSTRUCTOR:
case LAMBDA_EXPR:
- tpvis = type_visibility (TREE_TYPE (*tp));
+ tpvis = type_visibility (TREE_TYPE (t));
break;
+ case TEMPLATE_DECL:
+ if (DECL_ALIAS_TEMPLATE_P (t))
+ /* FIXME: We don't maintain TREE_PUBLIC / DECL_VISIBILITY for
+ alias templates so we can't trust it here (PR107906). */
+ break;
+ t = DECL_TEMPLATE_RESULT (t);
+ /* Fall through. */
case VAR_DECL:
case FUNCTION_DECL:
- if (! TREE_PUBLIC (*tp))
+ if (! TREE_PUBLIC (t))
tpvis = VISIBILITY_ANON;
else
- tpvis = DECL_VISIBILITY (*tp);
+ tpvis = DECL_VISIBILITY (t);
+ break;
+
+ case FIELD_DECL:
+ tpvis = type_visibility (DECL_CONTEXT (t));
break;
default: