This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C++ PATCH for c++/87080, ICE with -Wpessimizing-move
- From: Marek Polacek <polacek at redhat dot com>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>, Jason Merrill <jason at redhat dot com>
- Date: Fri, 24 Aug 2018 17:02:54 -0400
- Subject: C++ PATCH for c++/87080, ICE with -Wpessimizing-move
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;
+}