diff mbox series

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

Message ID 20240612184953.2734787-1-ppalka@redhat.com
State New
Headers show
Series c++: visibility wrt concept-id as targ [PR115283] | expand

Commit Message

Patrick Palka June 12, 2024, 6:49 p.m. UTC
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) <case TEMPLATE_DECL>: 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

Comments

Jason Merrill June 12, 2024, 8:28 p.m. UTC | #1
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) <case TEMPLATE_DECL>: 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 00000000000..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<class T>
> +concept same = true;
> +
> +template<bool B>
> +struct A { };
> +
> +template<class T>
> +void f(A<same<T>>) { }
> +
> +template void f<int>(A<true>);
diff mbox series

Patch

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 00000000000..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<class T>
+concept same = true;
+
+template<bool B>
+struct A { };
+
+template<class T>
+void f(A<same<T>>) { }
+
+template void f<int>(A<true>);