public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/100366] New: spurious warning - std::vector::clear followed by std::vector::insert(vec.end(), ...) with -O2
@ 2021-05-01  2:36 mrsam@courier-mta.com
  2021-05-02 11:27 ` [Bug tree-optimization/100366] " glisse at gcc dot gnu.org
                   ` (19 more replies)
  0 siblings, 20 replies; 21+ messages in thread
From: mrsam@courier-mta.com @ 2021-05-01  2:36 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 100366
           Summary: spurious warning - std::vector::clear followed by
                    std::vector::insert(vec.end(), ...) with -O2
           Product: gcc
           Version: 11.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mrsam@courier-mta.com
  Target Milestone: ---

I'm seeing this with both gcc 11.1 on: https://godbolt.org/z/1Wv9jj3r1

and gcc (GCC) 11.0.1 20210324 (Red Hat 11.0.1-0), below:

Compiling the following with -O2 -Wall -Werror:

#include <vector>
#include <memory>

static char UTC[4];

void func(std::vector<char> &vec)
{
        vec.clear();
        vec.insert(vec.end(), UTC, UTC+4);
}

This generates a massive complaint that boils down to:

/usr/include/c++/11/bits/stl_algobase.h:431:30: error: ‘void*
__builtin_memcpy(v
oid*, const void*, long unsigned int)’ writing 1 or more bytes into a region of 
size 0 overflows the destination [-Werror=stringop-overflow=]
  431 |             __builtin_memmove(__result, __first, sizeof(_Tp) * _Num);
      |             ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from
/usr/include/c++/11/x86_64-redhat-linux/bits/c++allocator.

...skipping 1 line
                 from /usr/include/c++/11/bits/allocator.h:46,
                 from /usr/include/c++/11/vector:64,
                 from t.C:1:

Removing vec.clear() makes this go away.

Adding vec.reserve(4) after vec.clear() makes this go away.

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

end of thread, other threads:[~2023-05-29 10:04 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-01  2:36 [Bug c++/100366] New: spurious warning - std::vector::clear followed by std::vector::insert(vec.end(), ...) with -O2 mrsam@courier-mta.com
2021-05-02 11:27 ` [Bug tree-optimization/100366] " glisse at gcc dot gnu.org
2021-05-03 17:51 ` msebor at gcc dot gnu.org
2021-05-03 21:02 ` mrsam@courier-mta.com
2021-05-04  7:39 ` rguenth at gcc dot gnu.org
2021-05-05 10:55 ` glisse at gcc dot gnu.org
2021-05-05 11:01 ` glisse at gcc dot gnu.org
2021-05-05 11:15 ` glisse at gcc dot gnu.org
2021-05-05 12:18 ` mrsam@courier-mta.com
2021-05-12 23:44 ` msebor at gcc dot gnu.org
2021-12-02 21:14 ` msebor at gcc dot gnu.org
2021-12-06 16:45 ` [Bug tree-optimization/100366] [11/12 Regression] " roystgnr at ices dot utexas.edu
2021-12-28 12:09 ` pinskia at gcc dot gnu.org
2022-01-20 14:03 ` rguenth at gcc dot gnu.org
2022-04-21  7:49 ` rguenth at gcc dot gnu.org
2022-07-05 10:07 ` [Bug tree-optimization/100366] [11/12/13 " hewillk at gmail dot com
2022-11-26 15:53 ` zeranoe at gmail dot com
2022-11-29 15:58 ` redi at gcc dot gnu.org
2022-11-29 17:14 ` cvs-commit at gcc dot gnu.org
2023-04-20 13:57 ` [Bug tree-optimization/100366] [11/12 " cvs-commit at gcc dot gnu.org
2023-05-29 10:04 ` jakub 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).