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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Or jump threading is splitting the code into two branches for N <= 1 and N >=
2, and then warning that the N >= 2 case would read past the end of the source
buffer. But that case never actually happens.

The constructor calls _M_construct which goes to:

      static void
      _S_copy(_CharT* __d, const _CharT* __s, size_type __n)
      {
        if (__n == 1)
          traits_type::assign(*__d, *__s);
        else
          traits_type::copy(__d, __s, __n);
      }

The N == 1 case is handled here, then char_traits<wchar_t>::copy does:

      static _GLIBCXX20_CONSTEXPR char_type*
      copy(char_type* __s1, const char_type* __s2, size_t __n)
      {
        if (__n == 0)
          return __s1;
#if __cplusplus >= 202002L
        if (std::__is_constant_evaluated())
          return __gnu_cxx::char_traits<char_type>::copy(__s1, __s2, __n);
#endif
        return wmemcpy(__s1, __s2, __n);
      }

So the N == 0 case is also handled here, so we only use wmemcpy for N >= 2. And
that would indeed read N * sizeof(wchar_t), i.e. 4 or more bytes, from L""
which is only 2 bytes.

But it's unreachable, because we take the if (__n == 0) branch.

Reply via email to