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 ccb771b278556dcf6b88457a7555dc0fd78f6522..258c6a9b76313faf8ee55d131c44ad84b0121e3a 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 122d9dcd4b3c923976a7390c28a9b8dd43b5715a..24647e29a5547bb4ea8b299dd25ed7604113c51e 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 67f4cdedbb043359f6cf7b0ce29e10ceb2546a17..3bd02e71eedda9edf9de2fdd2258f2b909003d52 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;
+}