]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Improve std::forward static assert message
authorJonathan Wakely <jwakely@redhat.com>
Tue, 28 Sep 2021 11:35:29 +0000 (12:35 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Fri, 26 Nov 2021 13:38:41 +0000 (13:38 +0000)
The previous message told you something was wrong, but not why it
happened or why it's bad. This changes it to explain that the function
is being misused.

Signed-off-by: Jonathan Wakely <jwakely@redhat.com>
libstdc++-v3/ChangeLog:

* include/bits/move.h (forward(remove_reference_t<T>&&)):
Improve text of static_assert.
* testsuite/20_util/forward/c_neg.cc: Adjust dg-error.
* testsuite/20_util/forward/f_neg.cc: Likewise.

(cherry picked from commit a11052d98db2f2a61841f0c5ee84de4ca1b3e296)

libstdc++-v3/include/bits/move.h
libstdc++-v3/testsuite/20_util/forward/c_neg.cc
libstdc++-v3/testsuite/20_util/forward/f_neg.cc

index 5a4dbdc823c7f945c175118cc57fdc0042584b39..b5a4020eeee6c065407064804ce885baf3edfb37 100644 (file)
@@ -86,8 +86,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     constexpr _Tp&&
     forward(typename std::remove_reference<_Tp>::type&& __t) noexcept
     {
-      static_assert(!std::is_lvalue_reference<_Tp>::value, "template argument"
-                   " substituting _Tp is an lvalue reference type");
+      static_assert(!std::is_lvalue_reference<_Tp>::value,
+         "std::forward must not be used to convert an rvalue to an lvalue");
       return static_cast<_Tp&&>(__t);
     }
 
index 8b6736d42f0c16173e6d12be0087a0e702024820..5e318ed67f44ea7529430c117de7c1dc58985997 100644 (file)
@@ -17,7 +17,7 @@
 // with this library; see the file COPYING3.  If not see
 // <http://www.gnu.org/licenses/>.
 
-// { dg-error "static assertion failed" "" { target *-*-* } 89 }
+// { dg-error "convert an rvalue to an lvalue" "" { target *-*-* } 0 }
 
 #include <list>
 
index 4b697f1cd5d83fcad74121c73d5a74d56754923e..c6cf880bd15142e46b762eac256fd2fa20958e5d 100644 (file)
@@ -17,7 +17,7 @@
 // with this library; see the file COPYING3.  If not see
 // <http://www.gnu.org/licenses/>.
 
-// { dg-error "static assertion failed" "" { target *-*-* } 89 }
+// { dg-error "convert an rvalue to an lvalue" "" { target *-*-* } 0 }
 
 #include <utility>