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

            Bug ID: 125368
           Summary: Gcc 16.1 gives incorrect array-bounds warning when
                    using make_shared and string
           Product: gcc
           Version: 16.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: LJE at foss dot dk
  Target Milestone: ---

When compiling this code:

#include <memory>
#include <string>


struct Foo
{
    Foo(std::shared_ptr<std::string> message)
    {
    }
};


void doStuff()
{
    auto entry = std::make_shared<Foo>(
                std::make_shared<std::string>("foo"));
}

With gcc 16.1 and -Warray-bounds and -O2

It gives the following warning:

error: array subscript 'std::__cxx11::basic_string<char>[0]' is partly outside
array bounds of 'unsigned char [24]' [-Werror=array-bounds=]

See Godbolt example: https://godbolt.org/z/9sEb63nT6

It also seems to be a problem with the current trunk version on godbolt.

It is not a problem with GCC 15.2.

It might be related to bug 122197

BR
  Lars

Reply via email to