Re: [PATCH] c++: visibility wrt concept-id as targ [PR115283]

2024-06-12 Thread Jason Merrill

On 6/12/24 14:49, Patrick Palka wrote:

Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look
OK for trunk?


OK for trunk and 14, I'd say.


-- >8 --

It seems we don't maintain visibility flags for concepts either, so
min_vis_expr_r should ignore them for now, otherwise after r14-6789 we
incorrectly give function templates that use a concept-id in their
signature internal linkage.

PR c++/115283

gcc/cp/ChangeLog:

* decl2.cc (min_vis_expr_r) : Ignore
concepts.

gcc/testsuite/ChangeLog:

* g++.dg/template/linkage5.C: New test.
---
  gcc/cp/decl2.cc  |  5 +++--
  gcc/testsuite/g++.dg/template/linkage5.C | 14 ++
  2 files changed, 17 insertions(+), 2 deletions(-)
  create mode 100644 gcc/testsuite/g++.dg/template/linkage5.C

diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc
index 7baff46a192..88e87ad60c6 100644
--- a/gcc/cp/decl2.cc
+++ b/gcc/cp/decl2.cc
@@ -2723,9 +2723,10 @@ min_vis_expr_r (tree *tp, int */*walk_subtrees*/, void 
*data)
break;
  
  case TEMPLATE_DECL:

-  if (DECL_ALIAS_TEMPLATE_P (t))
+  if (DECL_ALIAS_TEMPLATE_P (t) || concept_definition_p (t))
/* FIXME: We don't maintain TREE_PUBLIC / DECL_VISIBILITY for
-  alias templates so we can't trust it here (PR107906).  */
+  alias templates so we can't trust it here (PR107906).  Ditto
+  for concepts.  */
break;
t = DECL_TEMPLATE_RESULT (t);
/* Fall through.  */
diff --git a/gcc/testsuite/g++.dg/template/linkage5.C 
b/gcc/testsuite/g++.dg/template/linkage5.C
new file mode 100644
index 000..1dbb0beb5ea
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/linkage5.C
@@ -0,0 +1,14 @@
+// PR c++/115283
+// { dg-final { scan-assembler "(weak|glob)\[^\n\]*_Z1fIiEv1AIX4sameIT_EEE" } }
+// { dg-do compile { target c++20 } }
+
+template
+concept same = true;
+
+template
+struct A { };
+
+template
+void f(A>) { }
+
+template void f(A);




[PATCH] c++: visibility wrt concept-id as targ [PR115283]

2024-06-12 Thread Patrick Palka
Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look
OK for trunk?

-- >8 --

It seems we don't maintain visibility flags for concepts either, so
min_vis_expr_r should ignore them for now, otherwise after r14-6789 we
incorrectly give function templates that use a concept-id in their
signature internal linkage.

PR c++/115283

gcc/cp/ChangeLog:

* decl2.cc (min_vis_expr_r) : Ignore
concepts.

gcc/testsuite/ChangeLog:

* g++.dg/template/linkage5.C: New test.
---
 gcc/cp/decl2.cc  |  5 +++--
 gcc/testsuite/g++.dg/template/linkage5.C | 14 ++
 2 files changed, 17 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/template/linkage5.C

diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc
index 7baff46a192..88e87ad60c6 100644
--- a/gcc/cp/decl2.cc
+++ b/gcc/cp/decl2.cc
@@ -2723,9 +2723,10 @@ min_vis_expr_r (tree *tp, int */*walk_subtrees*/, void 
*data)
   break;
 
 case TEMPLATE_DECL:
-  if (DECL_ALIAS_TEMPLATE_P (t))
+  if (DECL_ALIAS_TEMPLATE_P (t) || concept_definition_p (t))
/* FIXME: We don't maintain TREE_PUBLIC / DECL_VISIBILITY for
-  alias templates so we can't trust it here (PR107906).  */
+  alias templates so we can't trust it here (PR107906).  Ditto
+  for concepts.  */
break;
   t = DECL_TEMPLATE_RESULT (t);
   /* Fall through.  */
diff --git a/gcc/testsuite/g++.dg/template/linkage5.C 
b/gcc/testsuite/g++.dg/template/linkage5.C
new file mode 100644
index 000..1dbb0beb5ea
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/linkage5.C
@@ -0,0 +1,14 @@
+// PR c++/115283
+// { dg-final { scan-assembler "(weak|glob)\[^\n\]*_Z1fIiEv1AIX4sameIT_EEE" } }
+// { dg-do compile { target c++20 } }
+
+template
+concept same = true;
+
+template
+struct A { };
+
+template
+void f(A>) { }
+
+template void f(A);
-- 
2.45.2.457.g8d94cfb545