public inbox for systemtap@sourceware.org
 help / color / mirror / Atom feed
* [Bug dyninst/28790] New: Replace deprecated C++98 junk with lambdas
@ 2022-01-18 11:40 jwakely.gcc at gmail dot com
  2022-01-18 11:41 ` [Bug dyninst/28790] " jwakely.gcc at gmail dot com
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: jwakely.gcc at gmail dot com @ 2022-01-18 11:40 UTC (permalink / raw)
  To: systemtap

https://sourceware.org/bugzilla/show_bug.cgi?id=28790

            Bug ID: 28790
           Summary: Replace deprecated C++98 junk with lambdas
           Product: systemtap
           Version: unspecified
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: dyninst
          Assignee: systemtap at sourceware dot org
          Reporter: jwakely.gcc at gmail dot com
  Target Milestone: ---

I have no idea what the correct Component is, sorry.

GCC 12 now (rightly) warns about systemtap's use of std::ptr_fun

util.cxx: In function 'void ltrim(std::string&)':
util.cxx:1764:56: error: 'std::pointer_to_unary_function<_Arg, _Result>
std::ptr_fun(_Result (*)(_Arg)) [with _Arg = int; _Result = int]' is
deprecated: use 'std::mem_fn' instead [-Werror=deprecated-declarations]
 1764 |                        std::not1(std::ptr_fun<int,
int>(std::isspace))));
      |                                  ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
In file included from
/nix/store/w4d0lkjirdzr19cqdq428j0kqlzc4lgd-gcc-12.0.0/include/c++/12.0.0/string:48,
                 from util.h:8,
                 from util.cxx:17:
/nix/store/w4d0lkjirdzr19cqdq428j0kqlzc4lgd-gcc-12.0.0/include/c++/12.0.0/bits/stl_function.h:1126:5:
note: declared here
 1126 |     ptr_fun(_Result (*__x)(_Arg))
      |     ^~~~~~~
util.cxx:1764:33: error: 'constexpr std::unary_negate<_Predicate>
std::not1(const _Predicate&) [with _Predicate = pointer_to_unary_function<int,
int>]' is deprecated: use 'std::not_fn' instead
[-Werror=deprecated-declarations]
 1764 |                        std::not1(std::ptr_fun<int,
int>(std::isspace))));
      |                        ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from
/nix/store/w4d0lkjirdzr19cqdq428j0kqlzc4lgd-gcc-12.0.0/include/c++/12.0.0/string:48,
                 from util.h:8,
                 from util.cxx:17:
/nix/store/w4d0lkjirdzr19cqdq428j0kqlzc4lgd-gcc-12.0.0/include/c++/12.0.0/bits/stl_function.h:1046:5:
note: declared here
 1046 |     not1(const _Predicate& __pred)
      |     ^~~~
util.cxx: In function 'void rtrim(std::string&)':
util.cxx:1772:43: error: 'std::pointer_to_unary_function<_Arg, _Result>
std::ptr_fun(_Result (*)(_Arg)) [with _Arg = int; _Result = int]' is
deprecated: use 'std::mem_fn' instead [-Werror=deprecated-declarations]
 1772 |           std::not1(std::ptr_fun<int, int>(std::isspace))).base(),
s.end());
      |                     ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
In file included from
/nix/store/w4d0lkjirdzr19cqdq428j0kqlzc4lgd-gcc-12.0.0/include/c++/12.0.0/string:48,
                 from util.h:8,
                 from util.cxx:17:
/nix/store/w4d0lkjirdzr19cqdq428j0kqlzc4lgd-gcc-12.0.0/include/c++/12.0.0/bits/stl_function.h:1126:5:
note: declared here
 1126 |     ptr_fun(_Result (*__x)(_Arg))
      |     ^~~~~~~
util.cxx:1772:20: error: 'constexpr std::unary_negate<_Predicate>
std::not1(const _Predicate&) [with _Predicate = pointer_to_unary_function<int,
int>]' is deprecated: use 'std::not_fn' instead
[-Werror=deprecated-declarations]
 1772 |           std::not1(std::ptr_fun<int, int>(std::isspace))).base(),
s.end());
      |           ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from
/nix/store/w4d0lkjirdzr19cqdq428j0kqlzc4lgd-gcc-12.0.0/include/c++/12.0.0/string:48,
                 from util.h:8,
                 from util.cxx:17:
/nix/store/w4d0lkjirdzr19cqdq428j0kqlzc4lgd-gcc-12.0.0/include/c++/12.0.0/bits/stl_function.h:1046:5:
note: declared here
 1046 |     not1(const _Predicate& __pred)
      |     ^~~~
cc1plus: all warnings being treated as errors

std::ptr_fun has not been part of the C++ standard since C++17, so you should
avoid using it (or ensure you compile as C++14).

The code is wrong for platforms with signed char anyway, with potentially
undefined behaviour. The argument to std::isspace(int) must have the value of
an unsigned char, i.e. it must be between (int)0 and (int)255. If you call it
with a signed char that has a negative value, you get a negative int, which is
outside the allowed range.

You can kill two birds with one stone by just getting rid of the std::ptr_fun
uses entirely:

diff --git a/util.cxx b/util.cxx
index c20f76003..76c751f18 100644
--- a/util.cxx
+++ b/util.cxx
@@ -1763,7 +1763,7 @@ ltrim(std::string &s)
 {
   s.erase(s.begin(),
          std::find_if(s.begin(), s.end(),
-                      std::not1(std::ptr_fun<int, int>(std::isspace))));
+                      [](unsigned char c) { return !std::isspace(c); }));
 }

 // trim from end (in place)
@@ -1771,7 +1771,7 @@ void
 rtrim(std::string &s)
 {
   s.erase(std::find_if(s.rbegin(), s.rend(),
-         std::not1(std::ptr_fun<int, int>(std::isspace))).base(), s.end());
+         [](unsigned char c) { return !std::isspace(c); }).base(), s.end());
 }

 // trim from both ends (in place)

-- 
You are receiving this mail because:
You are the assignee for the bug.

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2022-01-24 23:33 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-18 11:40 [Bug dyninst/28790] New: Replace deprecated C++98 junk with lambdas jwakely.gcc at gmail dot com
2022-01-18 11:41 ` [Bug dyninst/28790] " jwakely.gcc at gmail dot com
2022-01-18 21:02 ` fche at redhat dot com
2022-01-24 18:59 ` me at serhei dot io
2022-01-24 22:45 ` jwakely.gcc at gmail dot com
2022-01-24 22:47 ` jwakely.gcc at gmail dot com
2022-01-24 23:22 ` me at serhei dot io
2022-01-24 23:30 ` jwakely.gcc at gmail dot com
2022-01-24 23:33 ` me at serhei dot io

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).