bug-binutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug gold/28417] std::string no longer allows accepting nullptr_t since


From: jwakely.gcc at gmail dot com
Subject: [Bug gold/28417] std::string no longer allows accepting nullptr_t since it is undefined behavior after yesterday's change on libstdc++.
Date: Tue, 05 Oct 2021 08:06:19 +0000

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

--- Comment #4 from Jonathan Wakely <jwakely.gcc at gmail dot com> ---
Yes, the patch is correct.

To construct an empty string either use "" as the initializer, or just use the
default constructor. Creating a string from NULL or nullptr is completely bogus
and has been undefined behaviour since C++98:

  basic_string(const charT* s, const Allocator& a = Allocator());

  Requires: s shall not be a null pointer.

And GCC's std::string has turned that into an exception since forever:

        // NB: Not required, but considered best practice.
        if (__gnu_cxx::__is_null_pointer(__beg) && __beg != __end)
          std::__throw_logic_error(__N("basic_string::"
                                       "_M_construct null not valid"));


Which suggests neither of these pieces of code ever executes, so could be
removed.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]