From: Jonathan Wakely Date: Tue, 28 Sep 2021 11:35:29 +0000 (+0100) Subject: libstdc++: Improve std::forward static assert message X-Git-Tag: releases/gcc-10.4.0~568 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=453a8f3d3966f024fae8b8bb40f968e4be2b458e;p=thirdparty%2Fgcc.git libstdc++: Improve std::forward static assert message 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 libstdc++-v3/ChangeLog: * include/bits/move.h (forward(remove_reference_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) --- diff --git a/libstdc++-v3/include/bits/move.h b/libstdc++-v3/include/bits/move.h index 5a4dbdc823c7..b5a4020eeee6 100644 --- a/libstdc++-v3/include/bits/move.h +++ b/libstdc++-v3/include/bits/move.h @@ -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); } diff --git a/libstdc++-v3/testsuite/20_util/forward/c_neg.cc b/libstdc++-v3/testsuite/20_util/forward/c_neg.cc index 8b6736d42f0c..5e318ed67f44 100644 --- a/libstdc++-v3/testsuite/20_util/forward/c_neg.cc +++ b/libstdc++-v3/testsuite/20_util/forward/c_neg.cc @@ -17,7 +17,7 @@ // with this library; see the file COPYING3. If not see // . -// { dg-error "static assertion failed" "" { target *-*-* } 89 } +// { dg-error "convert an rvalue to an lvalue" "" { target *-*-* } 0 } #include diff --git a/libstdc++-v3/testsuite/20_util/forward/f_neg.cc b/libstdc++-v3/testsuite/20_util/forward/f_neg.cc index 4b697f1cd5d8..c6cf880bd151 100644 --- a/libstdc++-v3/testsuite/20_util/forward/f_neg.cc +++ b/libstdc++-v3/testsuite/20_util/forward/f_neg.cc @@ -17,7 +17,7 @@ // with this library; see the file COPYING3. If not see // . -// { dg-error "static assertion failed" "" { target *-*-* } 89 } +// { dg-error "convert an rvalue to an lvalue" "" { target *-*-* } 0 } #include