https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106020
Bug ID: 106020 Summary: Spurious warnings about stringop overflows only with LTO Product: gcc Version: 12.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: lto Assignee: unassigned at gcc dot gnu.org Reporter: matt at godbolt dot org CC: marxin at gcc dot gnu.org Target Milestone: --- When using Howard Hinnant's date library, and GCC 12.1 on x86, and then with LTO enabled, there are many apparently spurious errors after the read.constprop pass: /opt/compiler-explorer/libs/date/v3.0.1/include/date/date.h: In function 'read.constprop': /opt/compiler-explorer/libs/date/v3.0.1/include/date/date.h:6506:15: note: destination object 'buf' of size 11 6506 | CharT buf[std::numeric_limits<unsigned>::digits10+2u] = {}; It has proven tricky to get a smaller case but https://godbolt.org/z/hPaqz7TY1 demonstrates it with an inline version of date.h - a smaller version that doesn't inline the date library is https://godbolt.org/z/e75YG6ano and the code amounts to: std::chrono::system_clock::time_point parse_datetime(const std::string &sv) { std::istringstream ss{sv}; std::chrono::system_clock::time_point tp; ss >> date::parse("%FT%T%Z", tp); // ignoring errors for simplicity return tp; } (though it has to be linked in a separate TU with LTO enabled to trigger the issues). I initially filed this as a bug in the date library itself: https://github.com/HowardHinnant/date/issues/740 but we now believe this is a compiler issue. Compiling with GCC 11 or earlier, or with clang, or without LTO doesn't trigger these warnings.