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

            Bug ID: 118521
           Summary: [15 regression] std::vector Wstringop-overflow false
                    positive
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gnu.ojxq8 at dralias dot com
  Target Milestone: ---

Wstringop-overflow will hit when using the insert and push_back method on a
char vector.

Code:

#include <vector>
int main() {
    std::vector<char> v{1, 2};
    v.insert(v.end(), 2, 0);
    v.push_back(1);
}

Warning:

/opt/compiler-explorer/gcc-trunk-20250116/include/c++/15.0.1/bits/new_allocator.h:191:11:
warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=]

Godbolt:

https://godbolt.org/z/Y1EcEo4fd

Reply via email to