* [PATCH] c++: Clear uninstantiated friend flag when instantiating [PR104234]
@ 2023-11-23 12:54 Nathaniel Shead
2023-11-23 13:40 ` Nathaniel Shead
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Nathaniel Shead @ 2023-11-23 12:54 UTC (permalink / raw)
To: gcc-patches; +Cc: Jason Merrill, Nathan Sidwell, Patrick Palka
Bootstrapped and regtested on x86_64-pc-linux-gnu. I don't have write
access.
-- >8 --
Otherwise attempting to get the originating module declaration ICEs
because the DECL_CHAIN of an instantiated friend template is no longer
its context.
PR c++/104234
PR c++/112580
gcc/cp/ChangeLog:
* pt.cc (tsubst_template_decl):
gcc/testsuite/ChangeLog:
* g++.dg/modules/pr104234.C: New test.
Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
---
gcc/cp/pt.cc | 2 ++
gcc/testsuite/g++.dg/modules/pr104234.C | 16 ++++++++++++++++
2 files changed, 18 insertions(+)
create mode 100644 gcc/testsuite/g++.dg/modules/pr104234.C
diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index ed681afb5d4..5e10a523e1a 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -14789,6 +14789,8 @@ tsubst_template_decl (tree t, tree args, tsubst_flags_t complain,
if (PRIMARY_TEMPLATE_P (t))
DECL_PRIMARY_TEMPLATE (r) = r;
+ DECL_UNINSTANTIATED_TEMPLATE_FRIEND_P (r) = false;
+
if (!lambda_fntype && !class_p)
{
/* Record this non-type partial instantiation. */
diff --git a/gcc/testsuite/g++.dg/modules/pr104234.C b/gcc/testsuite/g++.dg/modules/pr104234.C
new file mode 100644
index 00000000000..d81f0d435bc
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/pr104234.C
@@ -0,0 +1,16 @@
+// PR c++/104234
+// { dg-additional-options "-fmodules-ts" }
+
+template <typename> struct _Node_handle_common {
+ template <typename> friend class _Rb_tree;
+};
+struct _Hashtable {
+ using node_type = _Node_handle_common<int>;
+ node_type __trans_tmp_1;
+};
+template <typename> class _Rb_tree {
+ struct _Rb_tree_impl {
+ _Rb_tree_impl();
+ } _M_impl;
+};
+_Rb_tree<int> _M_tmap_;
--
2.42.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] c++: Clear uninstantiated friend flag when instantiating [PR104234]
2023-11-23 12:54 [PATCH] c++: Clear uninstantiated friend flag when instantiating [PR104234] Nathaniel Shead
@ 2023-11-23 13:40 ` Nathaniel Shead
2023-12-10 18:35 ` Jason Merrill
2023-11-23 17:13 ` Patrick Palka
2023-11-23 17:47 ` Marek Polacek
2 siblings, 1 reply; 5+ messages in thread
From: Nathaniel Shead @ 2023-11-23 13:40 UTC (permalink / raw)
To: gcc-patches; +Cc: Jason Merrill, Nathan Sidwell, Patrick Palka
Sorry, I just noticed I hadn't actually filled in the changelog. It
should say "Clear DECL_UNINSTANTIATED_TEMPLATE_FRIEND_P."
On Thu, Nov 23, 2023 at 11:54 PM Nathaniel Shead
<nathanieloshead@gmail.com> wrote:
>
> Bootstrapped and regtested on x86_64-pc-linux-gnu. I don't have write
> access.
>
> -- >8 --
>
> Otherwise attempting to get the originating module declaration ICEs
> because the DECL_CHAIN of an instantiated friend template is no longer
> its context.
>
> PR c++/104234
> PR c++/112580
>
> gcc/cp/ChangeLog:
>
> * pt.cc (tsubst_template_decl):
>
> gcc/testsuite/ChangeLog:
>
> * g++.dg/modules/pr104234.C: New test.
>
> Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
> ---
> gcc/cp/pt.cc | 2 ++
> gcc/testsuite/g++.dg/modules/pr104234.C | 16 ++++++++++++++++
> 2 files changed, 18 insertions(+)
> create mode 100644 gcc/testsuite/g++.dg/modules/pr104234.C
>
> diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
> index ed681afb5d4..5e10a523e1a 100644
> --- a/gcc/cp/pt.cc
> +++ b/gcc/cp/pt.cc
> @@ -14789,6 +14789,8 @@ tsubst_template_decl (tree t, tree args, tsubst_flags_t complain,
> if (PRIMARY_TEMPLATE_P (t))
> DECL_PRIMARY_TEMPLATE (r) = r;
>
> + DECL_UNINSTANTIATED_TEMPLATE_FRIEND_P (r) = false;
> +
> if (!lambda_fntype && !class_p)
> {
> /* Record this non-type partial instantiation. */
> diff --git a/gcc/testsuite/g++.dg/modules/pr104234.C b/gcc/testsuite/g++.dg/modules/pr104234.C
> new file mode 100644
> index 00000000000..d81f0d435bc
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/modules/pr104234.C
> @@ -0,0 +1,16 @@
> +// PR c++/104234
> +// { dg-additional-options "-fmodules-ts" }
> +
> +template <typename> struct _Node_handle_common {
> + template <typename> friend class _Rb_tree;
> +};
> +struct _Hashtable {
> + using node_type = _Node_handle_common<int>;
> + node_type __trans_tmp_1;
> +};
> +template <typename> class _Rb_tree {
> + struct _Rb_tree_impl {
> + _Rb_tree_impl();
> + } _M_impl;
> +};
> +_Rb_tree<int> _M_tmap_;
> --
> 2.42.0
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] c++: Clear uninstantiated friend flag when instantiating [PR104234]
2023-11-23 12:54 [PATCH] c++: Clear uninstantiated friend flag when instantiating [PR104234] Nathaniel Shead
2023-11-23 13:40 ` Nathaniel Shead
@ 2023-11-23 17:13 ` Patrick Palka
2023-11-23 17:47 ` Marek Polacek
2 siblings, 0 replies; 5+ messages in thread
From: Patrick Palka @ 2023-11-23 17:13 UTC (permalink / raw)
To: Nathaniel Shead; +Cc: gcc-patches, Jason Merrill, Nathan Sidwell, Patrick Palka
On Thu, 23 Nov 2023, Nathaniel Shead wrote:
> Bootstrapped and regtested on x86_64-pc-linux-gnu. I don't have write
> access.
>
> -- >8 --
>
> Otherwise attempting to get the originating module declaration ICEs
> because the DECL_CHAIN of an instantiated friend template is no longer
> its context.
Thanks for the patch! I arrived at a similar fix back in January[1],
which Nathan reviewed[2], which then fell through the cracks... My
patch was perhaps too ambitious as it tried to fix the ICE as well
as a follow-up module attachment issue. But just clearing
DECL_UNINSTANTIATED_TEMPLATE_FRIEND_P (either in tsubst_template_decl or
more narrowly in tsubst_friend_class) seems pretty clearly correct and
fixes the reported ICEs so LGTM :) Thanks again!
[1]: https://gcc.gnu.org/pipermail/gcc-patches/2023-January/610593.html
[2]: https://gcc.gnu.org/pipermail/gcc-patches/2023-February/611215.html
>
> PR c++/104234
> PR c++/112580
>
> gcc/cp/ChangeLog:
>
> * pt.cc (tsubst_template_decl):
>
> gcc/testsuite/ChangeLog:
>
> * g++.dg/modules/pr104234.C: New test.
>
> Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
> ---
> gcc/cp/pt.cc | 2 ++
> gcc/testsuite/g++.dg/modules/pr104234.C | 16 ++++++++++++++++
> 2 files changed, 18 insertions(+)
> create mode 100644 gcc/testsuite/g++.dg/modules/pr104234.C
>
> diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
> index ed681afb5d4..5e10a523e1a 100644
> --- a/gcc/cp/pt.cc
> +++ b/gcc/cp/pt.cc
> @@ -14789,6 +14789,8 @@ tsubst_template_decl (tree t, tree args, tsubst_flags_t complain,
> if (PRIMARY_TEMPLATE_P (t))
> DECL_PRIMARY_TEMPLATE (r) = r;
>
> + DECL_UNINSTANTIATED_TEMPLATE_FRIEND_P (r) = false;
> +
> if (!lambda_fntype && !class_p)
> {
> /* Record this non-type partial instantiation. */
> diff --git a/gcc/testsuite/g++.dg/modules/pr104234.C b/gcc/testsuite/g++.dg/modules/pr104234.C
> new file mode 100644
> index 00000000000..d81f0d435bc
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/modules/pr104234.C
> @@ -0,0 +1,16 @@
> +// PR c++/104234
> +// { dg-additional-options "-fmodules-ts" }
> +
> +template <typename> struct _Node_handle_common {
> + template <typename> friend class _Rb_tree;
> +};
> +struct _Hashtable {
> + using node_type = _Node_handle_common<int>;
> + node_type __trans_tmp_1;
> +};
> +template <typename> class _Rb_tree {
> + struct _Rb_tree_impl {
> + _Rb_tree_impl();
> + } _M_impl;
> +};
> +_Rb_tree<int> _M_tmap_;
> --
> 2.42.0
>
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] c++: Clear uninstantiated friend flag when instantiating [PR104234]
2023-11-23 12:54 [PATCH] c++: Clear uninstantiated friend flag when instantiating [PR104234] Nathaniel Shead
2023-11-23 13:40 ` Nathaniel Shead
2023-11-23 17:13 ` Patrick Palka
@ 2023-11-23 17:47 ` Marek Polacek
2 siblings, 0 replies; 5+ messages in thread
From: Marek Polacek @ 2023-11-23 17:47 UTC (permalink / raw)
To: Nathaniel Shead; +Cc: gcc-patches, Jason Merrill, Nathan Sidwell, Patrick Palka
On Thu, Nov 23, 2023 at 11:54:48PM +1100, Nathaniel Shead wrote:
> Bootstrapped and regtested on x86_64-pc-linux-gnu. I don't have write
> access.
Based on your great contributions, you should get yourself write access;
please follow <https://gcc.gnu.org/gitwrite.html>. I'm not certain the
rules allow me to be your sponsor, but I'm sure Jason or Nathan will
gladly approve.
Marek
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] c++: Clear uninstantiated friend flag when instantiating [PR104234]
2023-11-23 13:40 ` Nathaniel Shead
@ 2023-12-10 18:35 ` Jason Merrill
0 siblings, 0 replies; 5+ messages in thread
From: Jason Merrill @ 2023-12-10 18:35 UTC (permalink / raw)
To: Nathaniel Shead, gcc-patches; +Cc: Nathan Sidwell, Patrick Palka
On 11/23/23 08:40, Nathaniel Shead wrote:
> Sorry, I just noticed I hadn't actually filled in the changelog. It
> should say "Clear DECL_UNINSTANTIATED_TEMPLATE_FRIEND_P."
OK with that change.
> On Thu, Nov 23, 2023 at 11:54 PM Nathaniel Shead
> <nathanieloshead@gmail.com> wrote:
>>
>> Bootstrapped and regtested on x86_64-pc-linux-gnu. I don't have write
>> access.
>>
>> -- >8 --
>>
>> Otherwise attempting to get the originating module declaration ICEs
>> because the DECL_CHAIN of an instantiated friend template is no longer
>> its context.
>>
>> PR c++/104234
>> PR c++/112580
>>
>> gcc/cp/ChangeLog:
>>
>> * pt.cc (tsubst_template_decl):
>>
>> gcc/testsuite/ChangeLog:
>>
>> * g++.dg/modules/pr104234.C: New test.
>>
>> Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
>> ---
>> gcc/cp/pt.cc | 2 ++
>> gcc/testsuite/g++.dg/modules/pr104234.C | 16 ++++++++++++++++
>> 2 files changed, 18 insertions(+)
>> create mode 100644 gcc/testsuite/g++.dg/modules/pr104234.C
>>
>> diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
>> index ed681afb5d4..5e10a523e1a 100644
>> --- a/gcc/cp/pt.cc
>> +++ b/gcc/cp/pt.cc
>> @@ -14789,6 +14789,8 @@ tsubst_template_decl (tree t, tree args, tsubst_flags_t complain,
>> if (PRIMARY_TEMPLATE_P (t))
>> DECL_PRIMARY_TEMPLATE (r) = r;
>>
>> + DECL_UNINSTANTIATED_TEMPLATE_FRIEND_P (r) = false;
>> +
>> if (!lambda_fntype && !class_p)
>> {
>> /* Record this non-type partial instantiation. */
>> diff --git a/gcc/testsuite/g++.dg/modules/pr104234.C b/gcc/testsuite/g++.dg/modules/pr104234.C
>> new file mode 100644
>> index 00000000000..d81f0d435bc
>> --- /dev/null
>> +++ b/gcc/testsuite/g++.dg/modules/pr104234.C
>> @@ -0,0 +1,16 @@
>> +// PR c++/104234
>> +// { dg-additional-options "-fmodules-ts" }
>> +
>> +template <typename> struct _Node_handle_common {
>> + template <typename> friend class _Rb_tree;
>> +};
>> +struct _Hashtable {
>> + using node_type = _Node_handle_common<int>;
>> + node_type __trans_tmp_1;
>> +};
>> +template <typename> class _Rb_tree {
>> + struct _Rb_tree_impl {
>> + _Rb_tree_impl();
>> + } _M_impl;
>> +};
>> +_Rb_tree<int> _M_tmap_;
>> --
>> 2.42.0
>>
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-12-10 18:35 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-23 12:54 [PATCH] c++: Clear uninstantiated friend flag when instantiating [PR104234] Nathaniel Shead
2023-11-23 13:40 ` Nathaniel Shead
2023-12-10 18:35 ` Jason Merrill
2023-11-23 17:13 ` Patrick Palka
2023-11-23 17:47 ` Marek Polacek
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).