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

2018-08-25 Thread Jason Merrill
OK.

On Sat, Aug 25, 2018 at 7:02 AM, Marek Polacek  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  
>
> 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 a <<(b);
> +};
> +a c();
> +template
> +a fn2()
> +{
> +  int d = 42;
> +  return c() << d;
> +}


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

2018-08-24 Thread Marek Polacek
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  

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 a <<(b);
+};
+a c();
+template
+a fn2()
+{
+  int d = 42;
+  return c() << d;
+}