re PR c++/87080 (ice in cp_get_fndecl_from_callee, at cp/cvt.c:965)
authorMarek Polacek <polacek@redhat.com>
Sun, 26 Aug 2018 16:31:27 +0000 (16:31 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Sun, 26 Aug 2018 16:31:27 +0000 (16:31 +0000)
PR c++/87080
* typeck.c (maybe_warn_pessimizing_move): Do nothing in a template.

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

From-SVN: r263862

gcc/cp/ChangeLog
gcc/cp/typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/Wpessimizing-move5.C [new file with mode: 0644]

index ccb771b..258c6a9 100644 (file)
@@ -1,3 +1,8 @@
+2018-08-26  Marek Polacek  <polacek@redhat.com>
+
+       PR c++/87080
+       * typeck.c (maybe_warn_pessimizing_move): Do nothing in a template.
+
 2018-08-24  Marek Polacek  <polacek@redhat.com>
 
        PR c++/67012
index 122d9dc..24647e2 100644 (file)
@@ -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;
index 67f4cde..3bd02e7 100644 (file)
@@ -1,3 +1,8 @@
+2018-08-26  Marek Polacek  <polacek@redhat.com>
+
+       PR c++/87080
+       * g++.dg/cpp0x/Wpessimizing-move5.C: New test.
+
 2018-08-25  Thomas Koenig  <tkoenig@gcc.gnu.org>
 
        PR libfortran/86704
diff --git a/gcc/testsuite/g++.dg/cpp0x/Wpessimizing-move5.C b/gcc/testsuite/g++.dg/cpp0x/Wpessimizing-move5.C
new file mode 100644 (file)
index 0000000..02ad211
--- /dev/null
@@ -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;
+}