diff mbox series

C++ PATCH for c++/87080, ICE with -Wpessimizing-move

Message ID 20180824210254.GC13632@redhat.com
State New
Headers show
Series C++ PATCH for c++/87080, ICE with -Wpessimizing-move | expand

Commit Message

Marek Polacek Aug. 24, 2018, 9:02 p.m. UTC
The problem in this testcase was that we were calling is_std_move_p from
template context, which breaks in cp_get_fndecl_from_callee.  This warning
is not meant to warn while parsing a template, so I think we should apply this.

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

2018-08-24  Marek Polacek  <polacek@redhat.com>

	PR c++/87080
	* typeck.c (maybe_warn_pessimizing_move): Do nothing in a template.

	* g++.dg/cpp0x/Wpessimizing-move5.C: New test.

Comments

Jason Merrill Aug. 25, 2018, 11:47 p.m. UTC | #1
OK.

On Sat, Aug 25, 2018 at 7:02 AM, Marek Polacek <polacek@redhat.com> wrote:
> The problem in this testcase was that we were calling is_std_move_p from
> template context, which breaks in cp_get_fndecl_from_callee.  This warning
> is not meant to warn while parsing a template, so I think we should apply this.
>
> Bootstrapped/regtested on x86_64-linux, ok for trunk?
>
> 2018-08-24  Marek Polacek  <polacek@redhat.com>
>
>         PR c++/87080
>         * typeck.c (maybe_warn_pessimizing_move): Do nothing in a template.
>
>         * g++.dg/cpp0x/Wpessimizing-move5.C: New test.
>
> diff --git gcc/cp/typeck.c gcc/cp/typeck.c
> index 122d9dcd4b3..24647e29a55 100644
> --- gcc/cp/typeck.c
> +++ gcc/cp/typeck.c
> @@ -9192,6 +9192,11 @@ maybe_warn_pessimizing_move (tree retval, tree functype)
>    if (cxx_dialect < cxx11)
>      return;
>
> +  /* Wait until instantiation time, since we can't gauge if we should do
> +     the NRVO until then.  */
> +  if (processing_template_decl)
> +    return;
> +
>    /* This is only interesting for class types.  */
>    if (!CLASS_TYPE_P (functype))
>      return;
> diff --git gcc/testsuite/g++.dg/cpp0x/Wpessimizing-move5.C gcc/testsuite/g++.dg/cpp0x/Wpessimizing-move5.C
> index e69de29bb2d..02ad2113505 100644
> --- gcc/testsuite/g++.dg/cpp0x/Wpessimizing-move5.C
> +++ gcc/testsuite/g++.dg/cpp0x/Wpessimizing-move5.C
> @@ -0,0 +1,14 @@
> +// PR c++/87080
> +// { dg-do compile { target c++11 } }
> +// { dg-options "-Wpessimizing-move" }
> +
> +struct a {
> +  template<typename b> a &operator<<(b);
> +};
> +a c();
> +template<typename>
> +a fn2()
> +{
> +  int d = 42;
> +  return c() << d;
> +}
diff mbox series

Patch

diff --git gcc/cp/typeck.c gcc/cp/typeck.c
index 122d9dcd4b3..24647e29a55 100644
--- gcc/cp/typeck.c
+++ gcc/cp/typeck.c
@@ -9192,6 +9192,11 @@  maybe_warn_pessimizing_move (tree retval, tree functype)
   if (cxx_dialect < cxx11)
     return;
 
+  /* Wait until instantiation time, since we can't gauge if we should do
+     the NRVO until then.  */
+  if (processing_template_decl)
+    return;
+
   /* This is only interesting for class types.  */
   if (!CLASS_TYPE_P (functype))
     return;
diff --git gcc/testsuite/g++.dg/cpp0x/Wpessimizing-move5.C gcc/testsuite/g++.dg/cpp0x/Wpessimizing-move5.C
index e69de29bb2d..02ad2113505 100644
--- gcc/testsuite/g++.dg/cpp0x/Wpessimizing-move5.C
+++ gcc/testsuite/g++.dg/cpp0x/Wpessimizing-move5.C
@@ -0,0 +1,14 @@ 
+// PR c++/87080
+// { dg-do compile { target c++11 } }
+// { dg-options "-Wpessimizing-move" }
+
+struct a {
+  template<typename b> a &operator<<(b);
+};
+a c();
+template<typename>
+a fn2()
+{
+  int d = 42;
+  return c() << d;
+}