public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/103534] New: [12 regression] Spurious -Wstringop-overflow warning with std::string concatencation
@ 2021-12-02 19:47 sss@li-snyder.org
  2021-12-02 21:03 ` [Bug c++/103534] " msebor at gcc dot gnu.org
                   ` (12 more replies)
  0 siblings, 13 replies; 14+ messages in thread
From: sss@li-snyder.org @ 2021-12-02 19:47 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103534

            Bug ID: 103534
           Summary: [12 regression] Spurious -Wstringop-overflow warning
                    with std::string concatencation
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: sss@li-snyder.org
  Target Milestone: ---

hi -

With a recent checkout of gcc12 (20211201) on a x86_64-pc-linux-gnu host,
compiling the following source with -O --std=c++20 gives a bogus
-Wstringop-overflow warning:

-- x.cc ---------------------------------------------------
#include <string>

std::string foo()
{
  return std::string("1234567890123456")  + std::string("");
}
-----------------------------------------------------------

$ g++ -c -O --std=c++20 x.cc
In file included from /usr/local/gcc/include/c++/12.0.0/string:40,
                 from x.cc:1:
In static member function ‘static constexpr std::char_traits<char>::char_type*
std::char_traits<char>::copy(std::char_traits<char>::char_type*, const
std::char_traits<char>::char_type*, std::size_t)’,
    inlined from ‘static constexpr void std::__cxx11::basic_string<_CharT,
_Traits, _Alloc>::_S_copy(_CharT*, const _CharT*,
std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type) [with _CharT =
char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’ at
/usr/local/gcc/include/c++/12.0.0/bits/basic_string.h:423:21,
    inlined from ‘constexpr std::__cxx11::basic_string<_CharT, _Traits,
_Allocator>& std::__cxx11::basic_string<_CharT, _Traits,
_Alloc>::_M_append(const _CharT*, std::__cxx11::basic_string<_CharT, _Traits,
_Alloc>::size_type) [with _CharT = char; _Traits = std::char_traits<char>;
_Alloc = std::allocator<char>]’ at
/usr/local/gcc/include/c++/12.0.0/bits/basic_string.tcc:417:19,
    inlined from ‘constexpr std::__cxx11::basic_string<_CharT, _Traits,
_Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::append(const
std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = char;
_Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’ at
/usr/local/gcc/include/c++/12.0.0/bits/basic_string.h:1385:25,
    inlined from ‘constexpr std::__cxx11::basic_string<_CharT, _Traits,
_Allocator> std::operator+(std::__cxx11::basic_string<_CharT, _Traits,
_Allocator>&&, std::__cxx11::basic_string<_CharT, _Traits, _Allocator>&&) [with
_CharT = char; _Traits = std::char_traits<char>; _Alloc =
std::allocator<char>]’ at
/usr/local/gcc/include/c++/12.0.0/bits/basic_string.h:3530:23,
    inlined from ‘std::string foo()’ at x.cc:5:59:
/usr/local/gcc/include/c++/12.0.0/bits/char_traits.h:426:56: warning: ‘void*
__builtin_memcpy(void*, const void*, long unsigned int)’ specified bound
between 18446744073709551600 and 18446744073709551615 exceeds maximum object
size 9223372036854775807 [-Wstringop-overflow=]
  426 |         return static_cast<char_type*>(__builtin_memcpy(__s1, __s2,
__n));
      |                                       
~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
$ 



Perhaps interestingly, the warning goes away if the first string literal
is less than 16 characters long.

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

end of thread, other threads:[~2021-12-13 16:11 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-02 19:47 [Bug c++/103534] New: [12 regression] Spurious -Wstringop-overflow warning with std::string concatencation sss@li-snyder.org
2021-12-02 21:03 ` [Bug c++/103534] " msebor at gcc dot gnu.org
2021-12-02 21:53 ` pinskia at gcc dot gnu.org
2021-12-02 23:02 ` redi at gcc dot gnu.org
2021-12-02 23:19 ` msebor at gcc dot gnu.org
2021-12-06  8:16 ` rguenth at gcc dot gnu.org
2021-12-10 16:29 ` jason at gcc dot gnu.org
2021-12-10 16:30 ` jason at gcc dot gnu.org
2021-12-10 16:37 ` jason at gcc dot gnu.org
2021-12-10 16:53 ` msebor at gcc dot gnu.org
2021-12-10 17:04 ` jakub at gcc dot gnu.org
2021-12-11  4:58 ` cvs-commit at gcc dot gnu.org
2021-12-13 16:11 ` jason at gcc dot gnu.org
2021-12-13 16:11 ` jason at gcc dot gnu.org

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).