public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* C++ PATCH for c++/89297 - ICE with OVERLOAD in template
@ 2019-02-13  5:13 Marek Polacek
  2019-02-13 16:44 ` Jason Merrill
  0 siblings, 1 reply; 5+ messages in thread
From: Marek Polacek @ 2019-02-13  5:13 UTC (permalink / raw)
  To: GCC Patches, Jason Merrill

Here we ICE because we're in a template and the constructor contains an
OVERLOAD, so calling check_narrowing -> maybe_constant_value crashes.

check_narrowing deliberately calls maybe_constant_value and not
fold_non_dependent_expr so as to avoid instantiating expressions twice.

So let's use instantiate_non_dependent_expr_sfinae to deal with the OVERLOAD;
fold_non_dependent_expr always calls maybe_constant_value and we can avoid
that call.

Bootstrapped/regtested on x86_64-linux, ok for trunk?

2019-02-12  Marek Polacek  <polacek@redhat.com>

	PR c++/89297 - ICE with OVERLOAD in template.
	* semantics.c (finish_compound_literal): Call
	instantiate_non_dependent_expr_sfinae.

	* g++.dg/cpp0x/initlist113.C: New test.

diff --git gcc/cp/semantics.c gcc/cp/semantics.c
index 786f18ab0c8..e89a38d3cba 100644
--- gcc/cp/semantics.c
+++ gcc/cp/semantics.c
@@ -2826,9 +2826,13 @@ finish_compound_literal (tree type, tree compound_literal,
     return error_mark_node;
   compound_literal = reshape_init (type, compound_literal, complain);
   if (SCALAR_TYPE_P (type)
-      && !BRACE_ENCLOSED_INITIALIZER_P (compound_literal)
-      && !check_narrowing (type, compound_literal, complain))
-    return error_mark_node;
+      && !BRACE_ENCLOSED_INITIALIZER_P (compound_literal))
+    {
+      compound_literal
+	= instantiate_non_dependent_expr_sfinae (compound_literal, complain);
+      if (!check_narrowing (type, compound_literal, complain))
+	return error_mark_node;
+    }
   if (TREE_CODE (type) == ARRAY_TYPE
       && TYPE_DOMAIN (type) == NULL_TREE)
     {
diff --git gcc/testsuite/g++.dg/cpp0x/initlist113.C gcc/testsuite/g++.dg/cpp0x/initlist113.C
new file mode 100644
index 00000000000..0b7e7ff606a
--- /dev/null
+++ gcc/testsuite/g++.dg/cpp0x/initlist113.C
@@ -0,0 +1,11 @@
+// PR c++/89297
+// { dg-do compile { target c++11 } }
+
+int id(int v) { return v; }
+float id(float v) { return v; }
+
+template <typename>
+int foo(int v)
+{
+    return int{id(v)};
+}

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: C++ PATCH for c++/89297 - ICE with OVERLOAD in template
  2019-02-13  5:13 C++ PATCH for c++/89297 - ICE with OVERLOAD in template Marek Polacek
@ 2019-02-13 16:44 ` Jason Merrill
  2019-02-13 16:59   ` Marek Polacek
  0 siblings, 1 reply; 5+ messages in thread
From: Jason Merrill @ 2019-02-13 16:44 UTC (permalink / raw)
  To: Marek Polacek, GCC Patches

On 2/13/19 12:13 AM, Marek Polacek wrote:
> Here we ICE because we're in a template and the constructor contains an
> OVERLOAD, so calling check_narrowing -> maybe_constant_value crashes.
> 
> check_narrowing deliberately calls maybe_constant_value and not
> fold_non_dependent_expr so as to avoid instantiating expressions twice.
> 
> So let's use instantiate_non_dependent_expr_sfinae to deal with the OVERLOAD;
> fold_non_dependent_expr always calls maybe_constant_value and we can avoid
> that call.
> 
> Bootstrapped/regtested on x86_64-linux, ok for trunk?
> 
> 2019-02-12  Marek Polacek  <polacek@redhat.com>
> 
> 	PR c++/89297 - ICE with OVERLOAD in template.
> 	* semantics.c (finish_compound_literal): Call
> 	instantiate_non_dependent_expr_sfinae.
> 
> 	* g++.dg/cpp0x/initlist113.C: New test.
> 
> diff --git gcc/cp/semantics.c gcc/cp/semantics.c
> index 786f18ab0c8..e89a38d3cba 100644
> --- gcc/cp/semantics.c
> +++ gcc/cp/semantics.c
> @@ -2826,9 +2826,13 @@ finish_compound_literal (tree type, tree compound_literal,
>       return error_mark_node;
>     compound_literal = reshape_init (type, compound_literal, complain);
>     if (SCALAR_TYPE_P (type)
> -      && !BRACE_ENCLOSED_INITIALIZER_P (compound_literal)
> -      && !check_narrowing (type, compound_literal, complain))
> -    return error_mark_node;
> +      && !BRACE_ENCLOSED_INITIALIZER_P (compound_literal))
> +    {
> +      compound_literal
> +	= instantiate_non_dependent_expr_sfinae (compound_literal, complain);
> +      if (!check_narrowing (type, compound_literal, complain))
> +	return error_mark_node;
> +    }

Since you change 'compound_literal', this seems to mean we will end up 
returning a constructor containing instantiated trees later 
instantiation isn't prepared to handle.

Jason

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: C++ PATCH for c++/89297 - ICE with OVERLOAD in template
  2019-02-13 16:44 ` Jason Merrill
@ 2019-02-13 16:59   ` Marek Polacek
  2019-02-13 21:03     ` Marek Polacek
  0 siblings, 1 reply; 5+ messages in thread
From: Marek Polacek @ 2019-02-13 16:59 UTC (permalink / raw)
  To: Jason Merrill; +Cc: GCC Patches

On Wed, Feb 13, 2019 at 11:44:42AM -0500, Jason Merrill wrote:
> On 2/13/19 12:13 AM, Marek Polacek wrote:
> > Here we ICE because we're in a template and the constructor contains an
> > OVERLOAD, so calling check_narrowing -> maybe_constant_value crashes.
> > 
> > check_narrowing deliberately calls maybe_constant_value and not
> > fold_non_dependent_expr so as to avoid instantiating expressions twice.
> > 
> > So let's use instantiate_non_dependent_expr_sfinae to deal with the OVERLOAD;
> > fold_non_dependent_expr always calls maybe_constant_value and we can avoid
> > that call.
> > 
> > Bootstrapped/regtested on x86_64-linux, ok for trunk?
> > 
> > 2019-02-12  Marek Polacek  <polacek@redhat.com>
> > 
> > 	PR c++/89297 - ICE with OVERLOAD in template.
> > 	* semantics.c (finish_compound_literal): Call
> > 	instantiate_non_dependent_expr_sfinae.
> > 
> > 	* g++.dg/cpp0x/initlist113.C: New test.
> > 
> > diff --git gcc/cp/semantics.c gcc/cp/semantics.c
> > index 786f18ab0c8..e89a38d3cba 100644
> > --- gcc/cp/semantics.c
> > +++ gcc/cp/semantics.c
> > @@ -2826,9 +2826,13 @@ finish_compound_literal (tree type, tree compound_literal,
> >       return error_mark_node;
> >     compound_literal = reshape_init (type, compound_literal, complain);
> >     if (SCALAR_TYPE_P (type)
> > -      && !BRACE_ENCLOSED_INITIALIZER_P (compound_literal)
> > -      && !check_narrowing (type, compound_literal, complain))
> > -    return error_mark_node;
> > +      && !BRACE_ENCLOSED_INITIALIZER_P (compound_literal))
> > +    {
> > +      compound_literal
> > +	= instantiate_non_dependent_expr_sfinae (compound_literal, complain);
> > +      if (!check_narrowing (type, compound_literal, complain))
> > +	return error_mark_node;
> > +    }
> 
> Since you change 'compound_literal', this seems to mean we will end up
> returning a constructor containing instantiated trees later instantiation
> isn't prepared to handle.

Interesting, I don't recall seeing that, and it certainly regtested fine.  So
then we could instantiate the complit just for the check_narrowing purposes
and proceed as before?

2019-02-13  Marek Polacek  <polacek@redhat.com>

	PR c++/89297 - ICE with OVERLOAD in template.
	* semantics.c (finish_compound_literal): Call
	instantiate_non_dependent_expr_sfinae.

	* g++.dg/cpp0x/initlist113.C: New test.

diff --git gcc/cp/semantics.c gcc/cp/semantics.c
index 786f18ab0c8..79f07f3a264 100644
--- gcc/cp/semantics.c
+++ gcc/cp/semantics.c
@@ -2826,9 +2826,13 @@ finish_compound_literal (tree type, tree compound_literal,
     return error_mark_node;
   compound_literal = reshape_init (type, compound_literal, complain);
   if (SCALAR_TYPE_P (type)
-      && !BRACE_ENCLOSED_INITIALIZER_P (compound_literal)
-      && !check_narrowing (type, compound_literal, complain))
-    return error_mark_node;
+      && !BRACE_ENCLOSED_INITIALIZER_P (compound_literal))
+    {
+      tree t = instantiate_non_dependent_expr_sfinae (compound_literal,
+						      complain);
+      if (!check_narrowing (type, t, complain))
+	return error_mark_node;
+    }
   if (TREE_CODE (type) == ARRAY_TYPE
       && TYPE_DOMAIN (type) == NULL_TREE)
     {
diff --git gcc/testsuite/g++.dg/cpp0x/initlist113.C gcc/testsuite/g++.dg/cpp0x/initlist113.C
new file mode 100644
index 00000000000..0b7e7ff606a
--- /dev/null
+++ gcc/testsuite/g++.dg/cpp0x/initlist113.C
@@ -0,0 +1,11 @@
+// PR c++/89297
+// { dg-do compile { target c++11 } }
+
+int id(int v) { return v; }
+float id(float v) { return v; }
+
+template <typename>
+int foo(int v)
+{
+    return int{id(v)};
+}

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: C++ PATCH for c++/89297 - ICE with OVERLOAD in template
  2019-02-13 16:59   ` Marek Polacek
@ 2019-02-13 21:03     ` Marek Polacek
  2019-02-13 21:31       ` Jason Merrill
  0 siblings, 1 reply; 5+ messages in thread
From: Marek Polacek @ 2019-02-13 21:03 UTC (permalink / raw)
  To: Jason Merrill; +Cc: GCC Patches

On Wed, Feb 13, 2019 at 11:59:05AM -0500, Marek Polacek wrote:
> On Wed, Feb 13, 2019 at 11:44:42AM -0500, Jason Merrill wrote:
> > On 2/13/19 12:13 AM, Marek Polacek wrote:
> > > Here we ICE because we're in a template and the constructor contains an
> > > OVERLOAD, so calling check_narrowing -> maybe_constant_value crashes.
> > > 
> > > check_narrowing deliberately calls maybe_constant_value and not
> > > fold_non_dependent_expr so as to avoid instantiating expressions twice.
> > > 
> > > So let's use instantiate_non_dependent_expr_sfinae to deal with the OVERLOAD;
> > > fold_non_dependent_expr always calls maybe_constant_value and we can avoid
> > > that call.
> > > 
> > > Bootstrapped/regtested on x86_64-linux, ok for trunk?
> > > 
> > > 2019-02-12  Marek Polacek  <polacek@redhat.com>
> > > 
> > > 	PR c++/89297 - ICE with OVERLOAD in template.
> > > 	* semantics.c (finish_compound_literal): Call
> > > 	instantiate_non_dependent_expr_sfinae.
> > > 
> > > 	* g++.dg/cpp0x/initlist113.C: New test.
> > > 
> > > diff --git gcc/cp/semantics.c gcc/cp/semantics.c
> > > index 786f18ab0c8..e89a38d3cba 100644
> > > --- gcc/cp/semantics.c
> > > +++ gcc/cp/semantics.c
> > > @@ -2826,9 +2826,13 @@ finish_compound_literal (tree type, tree compound_literal,
> > >       return error_mark_node;
> > >     compound_literal = reshape_init (type, compound_literal, complain);
> > >     if (SCALAR_TYPE_P (type)
> > > -      && !BRACE_ENCLOSED_INITIALIZER_P (compound_literal)
> > > -      && !check_narrowing (type, compound_literal, complain))
> > > -    return error_mark_node;
> > > +      && !BRACE_ENCLOSED_INITIALIZER_P (compound_literal))
> > > +    {
> > > +      compound_literal
> > > +	= instantiate_non_dependent_expr_sfinae (compound_literal, complain);
> > > +      if (!check_narrowing (type, compound_literal, complain))
> > > +	return error_mark_node;
> > > +    }
> > 
> > Since you change 'compound_literal', this seems to mean we will end up
> > returning a constructor containing instantiated trees later instantiation
> > isn't prepared to handle.
> 
> Interesting, I don't recall seeing that, and it certainly regtested fine.  So
> then we could instantiate the complit just for the check_narrowing purposes
> and proceed as before?

Now regtested/bootstrapped on x86_64-linux too.

> 2019-02-13  Marek Polacek  <polacek@redhat.com>
> 
> 	PR c++/89297 - ICE with OVERLOAD in template.
> 	* semantics.c (finish_compound_literal): Call
> 	instantiate_non_dependent_expr_sfinae.
> 
> 	* g++.dg/cpp0x/initlist113.C: New test.
> 
> diff --git gcc/cp/semantics.c gcc/cp/semantics.c
> index 786f18ab0c8..79f07f3a264 100644
> --- gcc/cp/semantics.c
> +++ gcc/cp/semantics.c
> @@ -2826,9 +2826,13 @@ finish_compound_literal (tree type, tree compound_literal,
>      return error_mark_node;
>    compound_literal = reshape_init (type, compound_literal, complain);
>    if (SCALAR_TYPE_P (type)
> -      && !BRACE_ENCLOSED_INITIALIZER_P (compound_literal)
> -      && !check_narrowing (type, compound_literal, complain))
> -    return error_mark_node;
> +      && !BRACE_ENCLOSED_INITIALIZER_P (compound_literal))
> +    {
> +      tree t = instantiate_non_dependent_expr_sfinae (compound_literal,
> +						      complain);
> +      if (!check_narrowing (type, t, complain))
> +	return error_mark_node;
> +    }
>    if (TREE_CODE (type) == ARRAY_TYPE
>        && TYPE_DOMAIN (type) == NULL_TREE)
>      {
> diff --git gcc/testsuite/g++.dg/cpp0x/initlist113.C gcc/testsuite/g++.dg/cpp0x/initlist113.C
> new file mode 100644
> index 00000000000..0b7e7ff606a
> --- /dev/null
> +++ gcc/testsuite/g++.dg/cpp0x/initlist113.C
> @@ -0,0 +1,11 @@
> +// PR c++/89297
> +// { dg-do compile { target c++11 } }
> +
> +int id(int v) { return v; }
> +float id(float v) { return v; }
> +
> +template <typename>
> +int foo(int v)
> +{
> +    return int{id(v)};
> +}

Marek

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: C++ PATCH for c++/89297 - ICE with OVERLOAD in template
  2019-02-13 21:03     ` Marek Polacek
@ 2019-02-13 21:31       ` Jason Merrill
  0 siblings, 0 replies; 5+ messages in thread
From: Jason Merrill @ 2019-02-13 21:31 UTC (permalink / raw)
  To: Marek Polacek; +Cc: GCC Patches

On Wed, Feb 13, 2019 at 4:03 PM Marek Polacek <polacek@redhat.com> wrote:
> On Wed, Feb 13, 2019 at 11:59:05AM -0500, Marek Polacek wrote:
> > On Wed, Feb 13, 2019 at 11:44:42AM -0500, Jason Merrill wrote:
> > > On 2/13/19 12:13 AM, Marek Polacek wrote:
> > > > Here we ICE because we're in a template and the constructor contains an
> > > > OVERLOAD, so calling check_narrowing -> maybe_constant_value crashes.
> > > >
> > > > check_narrowing deliberately calls maybe_constant_value and not
> > > > fold_non_dependent_expr so as to avoid instantiating expressions twice.
> > > >
> > > > So let's use instantiate_non_dependent_expr_sfinae to deal with the OVERLOAD;
> > > > fold_non_dependent_expr always calls maybe_constant_value and we can avoid
> > > > that call.
> > > >
> > > > Bootstrapped/regtested on x86_64-linux, ok for trunk?
> > > >
> > > > 2019-02-12  Marek Polacek  <polacek@redhat.com>
> > > >
> > > >   PR c++/89297 - ICE with OVERLOAD in template.
> > > >   * semantics.c (finish_compound_literal): Call
> > > >   instantiate_non_dependent_expr_sfinae.
> > > >
> > > >   * g++.dg/cpp0x/initlist113.C: New test.
> > > >
> > > > diff --git gcc/cp/semantics.c gcc/cp/semantics.c
> > > > index 786f18ab0c8..e89a38d3cba 100644
> > > > --- gcc/cp/semantics.c
> > > > +++ gcc/cp/semantics.c
> > > > @@ -2826,9 +2826,13 @@ finish_compound_literal (tree type, tree compound_literal,
> > > >       return error_mark_node;
> > > >     compound_literal = reshape_init (type, compound_literal, complain);
> > > >     if (SCALAR_TYPE_P (type)
> > > > -      && !BRACE_ENCLOSED_INITIALIZER_P (compound_literal)
> > > > -      && !check_narrowing (type, compound_literal, complain))
> > > > -    return error_mark_node;
> > > > +      && !BRACE_ENCLOSED_INITIALIZER_P (compound_literal))
> > > > +    {
> > > > +      compound_literal
> > > > + = instantiate_non_dependent_expr_sfinae (compound_literal, complain);
> > > > +      if (!check_narrowing (type, compound_literal, complain))
> > > > + return error_mark_node;
> > > > +    }
> > >
> > > Since you change 'compound_literal', this seems to mean we will end up
> > > returning a constructor containing instantiated trees later instantiation
> > > isn't prepared to handle.
> >
> > Interesting, I don't recall seeing that, and it certainly regtested fine.  So
> > then we could instantiate the complit just for the check_narrowing purposes
> > and proceed as before?
>
> Now regtested/bootstrapped on x86_64-linux too.

OK.

Jason

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-02-13 21:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-13  5:13 C++ PATCH for c++/89297 - ICE with OVERLOAD in template Marek Polacek
2019-02-13 16:44 ` Jason Merrill
2019-02-13 16:59   ` Marek Polacek
2019-02-13 21:03     ` Marek Polacek
2019-02-13 21:31       ` 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).