[Bug c++/80329] Poor location for array bounds warning

msebor at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Wed Feb 12 17:37:00 GMT 2020


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

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
   Last reconfirmed|                            |2020-2-12
                 CC|                            |msebor at gcc dot gnu.org
         Resolution|---                         |DUPLICATE
      Known to fail|                            |10.0, 7.3.0, 8.3.0, 9.2.0

--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
Confirmed.  These -Warray-bounds warnings don't include the inlining context. 
I posted a patch some time ago to add it
(https://gcc.gnu.org/ml/gcc-patches/2018-07/msg01286.html).  With it, the
output looks like that below.  I didn't commit the whole patch because it
caused some minor regressions in the test suite: the underlining of array
subscripts in references of multi-dimensional arrays becomes less accurate.  It
might be worth revisiting that decision since the lack of the inlining context
seems like more of a problem than the other issue.

I haven't checked if the inlining context below includes all the inlined
functions.  I've seen cases where it doesn't and I'm not sure what could be
done about those.

Anyway, I'll assume the lack of the inlining context is what you were referring
to so I'll resolve this as a dupe of pr86650.  If you had something else in
mind please reopen this (and say what).

Another thing still missing here even with the inlining context is a note
pointing to the referenced object.  The warning does include that note in many
cases but in this case the access is to the string literal which has no
location associated with it. 

In file included from
/build/gcc-trunk/x86_64-pc-linux-gnu/libstdc++-v3/include/string:56,
                 from pr80329.C:1:
In member function ‘void std::__cxx11::basic_string<_CharT, _Traits,
_Alloc>::_M_construct(_InIterator, _InIterator, std::forward_iterator_tag)
[with _FwdIterator = const char*; _CharT = char; _Traits =
std::char_traits<char>; _Alloc = std::allocator<char>]’,
    inlined from ‘void std::__cxx11::basic_string<_CharT, _Traits,
_Alloc>::_M_construct(_InIterator, _InIterator) [with _InIterator = const
char*; _CharT = char; _Traits = std::char_traits<char>; _Alloc =
std::allocator<char>]’ at
/build/gcc-trunk/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/basic_string.h:247:23,
    inlined from ‘std::__cxx11::basic_string<_CharT, _Traits,
_Alloc>::basic_string(const _CharT*, std::__cxx11::basic_string<_CharT,
_Traits, _Alloc>::size_type, const _Alloc&) [with _CharT = char; _Traits =
std::char_traits<char>; _Alloc = std::allocator<char>]’ at
/build/gcc-trunk/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/basic_string.h:513:21,
    inlined from ‘int main()’ at pr80329.C:5:22:
/build/gcc-trunk/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/basic_string.tcc:225:25:
warning: array subscript 2 is outside array bounds of ‘const char [1]’
[-Warray-bounds]
  225 |    { this->_S_copy_chars(_M_data(), __beg, __end); }
      |      ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~

*** This bug has been marked as a duplicate of bug 86650 ***


More information about the Gcc-bugs mailing list