public inbox for systemtap@sourceware.org
 help / color / mirror / Atom feed
From: "jwakely.gcc at gmail dot com" <sourceware-bugzilla@sourceware.org>
To: systemtap@sourceware.org
Subject: [Bug dyninst/28790] New: Replace deprecated C++98 junk with lambdas
Date: Tue, 18 Jan 2022 11:40:27 +0000	[thread overview]
Message-ID: <bug-28790-6586@http.sourceware.org/bugzilla/> (raw)

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.

             reply	other threads:[~2022-01-18 11:40 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-18 11:40 jwakely.gcc at gmail dot com [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-28790-6586@http.sourceware.org/bugzilla/ \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=systemtap@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).