* [PATCH] Fix PR c++/70332 (ICE due to aggregate initialization of NSDMI)
@ 2016-03-22 21:40 Patrick Palka
2016-03-22 22:33 ` Jason Merrill
0 siblings, 1 reply; 7+ messages in thread
From: Patrick Palka @ 2016-03-22 21:40 UTC (permalink / raw)
To: gcc-patches; +Cc: jason, Patrick Palka
With c++14 an NSDMI no longer makes a class type non-aggregate so it's
possible to perform aggregate initialization on a class that has an
NSDMI, but tsubst_copy() currently ICEs on a use of 'this' in such
a situation.
This patch makes tsubst_copy() handle a use of 'this' in an NSDMI as
part of an aggregate initialization. In that case current_class_ref
will be a PLACEHOLDER_EXPR (as set by get_nsdmi()) and this
PLACEHOLDER_EXPR will later get resolved to the true object by
replace_placeholders().
Does this patch look OK to commit after testing?
gcc/cp/ChangeLog:
PR c++/70332
* pt.c (tsubst_copy) [PARM_DECL]: Handle the use of 'this' in an
NSDMI that's part of an aggregrate initialization.
gcc/testsuite/ChangeLog:
PR c++/70332
* g++.dg/cpp1y/nsdmi-aggr5.C: New test.
---
gcc/cp/pt.c | 20 ++++++++++++++++----
gcc/testsuite/g++.dg/cpp1y/nsdmi-aggr5.C | 24 ++++++++++++++++++++++++
2 files changed, 40 insertions(+), 4 deletions(-)
create mode 100644 gcc/testsuite/g++.dg/cpp1y/nsdmi-aggr5.C
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index ebfc45b..49ef9d3 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -13878,10 +13878,22 @@ tsubst_copy (tree t, tree args, tsubst_flags_t complain, tree in_decl)
if (r == NULL_TREE)
{
/* We get here for a use of 'this' in an NSDMI. */
- if (DECL_NAME (t) == this_identifier
- && current_function_decl
- && DECL_CONSTRUCTOR_P (current_function_decl))
- return current_class_ptr;
+ if (DECL_NAME (t) == this_identifier)
+ {
+ /* We're processing an NSDMI as part of a constructor call. */
+ if (current_function_decl
+ && DECL_CONSTRUCTOR_P (current_function_decl))
+ return current_class_ptr;
+
+ /* Or as part of an aggregate initialization. */
+ if (cp_unevaluated_operand == 0
+ && current_class_ref
+ && TREE_CODE (current_class_ref) == PLACEHOLDER_EXPR)
+ {
+ gcc_assert (cxx_dialect >= cxx14);
+ return current_class_ptr;
+ }
+ }
/* This can happen for a parameter name used later in a function
declaration (such as in a late-specified return type). Just
diff --git a/gcc/testsuite/g++.dg/cpp1y/nsdmi-aggr5.C b/gcc/testsuite/g++.dg/cpp1y/nsdmi-aggr5.C
new file mode 100644
index 0000000..fe377c3
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/nsdmi-aggr5.C
@@ -0,0 +1,24 @@
+// PR c++/70332
+// { dg-do run { target c++14 } }
+
+template <class T>
+struct C
+{
+ T m;
+ T *n = &m;
+};
+
+C<int> c { };
+
+int
+main ()
+{
+ *c.n = 5;
+ if (c.m != 5)
+ __builtin_abort ();
+
+ C<int> d { 10 };
+ *d.n = *d.n + 1;
+ if (d.m != 11)
+ __builtin_abort ();
+}
--
2.8.0.rc3.27.gade0865
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] Fix PR c++/70332 (ICE due to aggregate initialization of NSDMI)
2016-03-22 21:40 [PATCH] Fix PR c++/70332 (ICE due to aggregate initialization of NSDMI) Patrick Palka
@ 2016-03-22 22:33 ` Jason Merrill
2016-03-22 22:45 ` Patrick Palka
0 siblings, 1 reply; 7+ messages in thread
From: Jason Merrill @ 2016-03-22 22:33 UTC (permalink / raw)
To: Patrick Palka, gcc-patches
On 03/22/2016 05:35 PM, Patrick Palka wrote:
> + if (cp_unevaluated_operand == 0
Why check this here?
Jason
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] Fix PR c++/70332 (ICE due to aggregate initialization of NSDMI)
2016-03-22 22:33 ` Jason Merrill
@ 2016-03-22 22:45 ` Patrick Palka
2016-03-23 1:33 ` Patrick Palka
0 siblings, 1 reply; 7+ messages in thread
From: Patrick Palka @ 2016-03-22 22:45 UTC (permalink / raw)
To: Jason Merrill; +Cc: GCC Patches
On Tue, Mar 22, 2016 at 6:00 PM, Jason Merrill <jason@redhat.com> wrote:
> On 03/22/2016 05:35 PM, Patrick Palka wrote:
>>
>> + if (cp_unevaluated_operand == 0
>
>
> Why check this here?
Just so that the change doesn't affect the behavior of tsubst_decl()
when cp_unevaluated_operand != 0. Presumably the existing code (10
lines below) handles that case just fine.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] Fix PR c++/70332 (ICE due to aggregate initialization of NSDMI)
2016-03-22 22:45 ` Patrick Palka
@ 2016-03-23 1:33 ` Patrick Palka
2016-03-23 13:05 ` Jason Merrill
0 siblings, 1 reply; 7+ messages in thread
From: Patrick Palka @ 2016-03-23 1:33 UTC (permalink / raw)
To: Jason Merrill; +Cc: GCC Patches
On Tue, Mar 22, 2016 at 6:12 PM, Patrick Palka <patrick@parcs.ath.cx> wrote:
> On Tue, Mar 22, 2016 at 6:00 PM, Jason Merrill <jason@redhat.com> wrote:
>> On 03/22/2016 05:35 PM, Patrick Palka wrote:
>>>
>>> + if (cp_unevaluated_operand == 0
>>
>>
>> Why check this here?
>
> Just so that the change doesn't affect the behavior of tsubst_decl()
> when cp_unevaluated_operand != 0. Presumably the existing code (10
> lines below) handles that case just fine.
Turns out that without the check we can trigger the cxx_dialect >=
cxx14 assert because in c++11 mode we can reach the assert through
get_defaulted_eh_spec() which increments cp_unevaluated_operand and
then calls get_nsdmi (..., /*in_ctor=*/false) causing
current_class_ref to get set to a PLACEHOLDER_EXPR.
So for example g++.dg/cpp0x/nsdmi-template2.C regresses with an ICE.
So it seems the cp_unevaluated_operand != 0 check is necessary as long
as the assert stays.
There are no regressions if both the cp_unevaluated_operand check and
the assert are removed however.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] Fix PR c++/70332 (ICE due to aggregate initialization of NSDMI)
2016-03-23 1:33 ` Patrick Palka
@ 2016-03-23 13:05 ` Jason Merrill
2016-03-23 13:25 ` Patrick Palka
0 siblings, 1 reply; 7+ messages in thread
From: Jason Merrill @ 2016-03-23 13:05 UTC (permalink / raw)
To: Patrick Palka; +Cc: GCC Patches
On 03/22/2016 07:12 PM, Patrick Palka wrote:
> On Tue, Mar 22, 2016 at 6:12 PM, Patrick Palka <patrick@parcs.ath.cx> wrote:
>> On Tue, Mar 22, 2016 at 6:00 PM, Jason Merrill <jason@redhat.com> wrote:
>>> On 03/22/2016 05:35 PM, Patrick Palka wrote:
>>>>
>>>> + if (cp_unevaluated_operand == 0
>>>
>>>
>>> Why check this here?
>>
>> Just so that the change doesn't affect the behavior of tsubst_decl()
>> when cp_unevaluated_operand != 0. Presumably the existing code (10
>> lines below) handles that case just fine.
>
> Turns out that without the check we can trigger the cxx_dialect >=
> cxx14 assert because in c++11 mode we can reach the assert through
> get_defaulted_eh_spec() which increments cp_unevaluated_operand and
> then calls get_nsdmi (..., /*in_ctor=*/false) causing
> current_class_ref to get set to a PLACEHOLDER_EXPR.
>
> So for example g++.dg/cpp0x/nsdmi-template2.C regresses with an ICE.
> So it seems the cp_unevaluated_operand != 0 check is necessary as long
> as the assert stays.
>
> There are no regressions if both the cp_unevaluated_operand check and
> the assert are removed however.
I think that's my preference.
Jason
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] Fix PR c++/70332 (ICE due to aggregate initialization of NSDMI)
2016-03-23 13:05 ` Jason Merrill
@ 2016-03-23 13:25 ` Patrick Palka
2016-03-23 13:52 ` Jason Merrill
0 siblings, 1 reply; 7+ messages in thread
From: Patrick Palka @ 2016-03-23 13:25 UTC (permalink / raw)
To: Jason Merrill; +Cc: Patrick Palka, GCC Patches
On Wed, 23 Mar 2016, Jason Merrill wrote:
> On 03/22/2016 07:12 PM, Patrick Palka wrote:
> > On Tue, Mar 22, 2016 at 6:12 PM, Patrick Palka <patrick@parcs.ath.cx> wrote:
> > > On Tue, Mar 22, 2016 at 6:00 PM, Jason Merrill <jason@redhat.com> wrote:
> > > > On 03/22/2016 05:35 PM, Patrick Palka wrote:
> > > > >
> > > > > + if (cp_unevaluated_operand == 0
> > > >
> > > >
> > > > Why check this here?
> > >
> > > Just so that the change doesn't affect the behavior of tsubst_decl()
> > > when cp_unevaluated_operand != 0. Presumably the existing code (10
> > > lines below) handles that case just fine.
> >
> > Turns out that without the check we can trigger the cxx_dialect >=
> > cxx14 assert because in c++11 mode we can reach the assert through
> > get_defaulted_eh_spec() which increments cp_unevaluated_operand and
> > then calls get_nsdmi (..., /*in_ctor=*/false) causing
> > current_class_ref to get set to a PLACEHOLDER_EXPR.
> >
> > So for example g++.dg/cpp0x/nsdmi-template2.C regresses with an ICE.
> > So it seems the cp_unevaluated_operand != 0 check is necessary as long
> > as the assert stays.
> >
> > There are no regressions if both the cp_unevaluated_operand check and
> > the assert are removed however.
>
> I think that's my preference.
>
> Jason
>
>
>
Done. Does this version look OK to commit after bootstrap + regtesting?
gcc/cp/ChangeLog:
PR c++/70332
* pt.c (tsubst_copy) [PARM_DECL]: Handle the use of 'this' in an
NSDMI that's part of an aggregrate initialization.
gcc/testsuite/ChangeLog:
PR c++/70332
* g++.dg/cpp1y/nsdmi-aggr5.C: New test.
---
gcc/cp/pt.c | 9 ++++++---
gcc/testsuite/g++.dg/cpp1y/nsdmi-aggr5.C | 24 ++++++++++++++++++++++++
2 files changed, 30 insertions(+), 3 deletions(-)
create mode 100644 gcc/testsuite/g++.dg/cpp1y/nsdmi-aggr5.C
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index ebfc45b..231d112 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -13877,10 +13877,13 @@ tsubst_copy (tree t, tree args, tsubst_flags_t complain, tree in_decl)
if (r == NULL_TREE)
{
- /* We get here for a use of 'this' in an NSDMI. */
+ /* We get here for a use of 'this' in an NSDMI as part of a
+ constructor call or as part of an aggregate initialization. */
if (DECL_NAME (t) == this_identifier
- && current_function_decl
- && DECL_CONSTRUCTOR_P (current_function_decl))
+ && ((current_function_decl
+ && DECL_CONSTRUCTOR_P (current_function_decl))
+ || (current_class_ref
+ && TREE_CODE (current_class_ref) == PLACEHOLDER_EXPR)))
return current_class_ptr;
/* This can happen for a parameter name used later in a function
diff --git a/gcc/testsuite/g++.dg/cpp1y/nsdmi-aggr5.C b/gcc/testsuite/g++.dg/cpp1y/nsdmi-aggr5.C
new file mode 100644
index 0000000..fe377c3
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/nsdmi-aggr5.C
@@ -0,0 +1,24 @@
+// PR c++/70332
+// { dg-do run { target c++14 } }
+
+template <class T>
+struct C
+{
+ T m;
+ T *n = &m;
+};
+
+C<int> c { };
+
+int
+main ()
+{
+ *c.n = 5;
+ if (c.m != 5)
+ __builtin_abort ();
+
+ C<int> d { 10 };
+ *d.n = *d.n + 1;
+ if (d.m != 11)
+ __builtin_abort ();
+}
--
2.8.0.rc3.27.gade0865
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] Fix PR c++/70332 (ICE due to aggregate initialization of NSDMI)
2016-03-23 13:25 ` Patrick Palka
@ 2016-03-23 13:52 ` Jason Merrill
0 siblings, 0 replies; 7+ messages in thread
From: Jason Merrill @ 2016-03-23 13:52 UTC (permalink / raw)
To: Patrick Palka; +Cc: GCC Patches
OK.
Jason
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2016-03-23 13:29 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-03-22 21:40 [PATCH] Fix PR c++/70332 (ICE due to aggregate initialization of NSDMI) Patrick Palka
2016-03-22 22:33 ` Jason Merrill
2016-03-22 22:45 ` Patrick Palka
2016-03-23 1:33 ` Patrick Palka
2016-03-23 13:05 ` Jason Merrill
2016-03-23 13:25 ` Patrick Palka
2016-03-23 13:52 ` Jason Merrill
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).