https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80329
Bug ID: 80329 Summary: Poor location for array bounds warning Product: gcc Version: 7.0.1 Status: UNCONFIRMED Keywords: diagnostic Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: redi at gcc dot gnu.org Target Milestone: --- #include <string> int main() { std::string s("", 2); } With -O2 -Wsystem-headers there's a valid warning, but with a useless location: In file included from /home/jwakely/gcc/7/include/c++/7.0.1/bits/stl_algobase.h:66:0, from /home/jwakely/gcc/7/include/c++/7.0.1/bits/char_traits.h:39, from /home/jwakely/gcc/7/include/c++/7.0.1/string:40, from s.cc:1: /home/jwakely/gcc/7/include/c++/7.0.1/bits/stl_iterator_base_funcs.h: In function ‘int main()’: /home/jwakely/gcc/7/include/c++/7.0.1/bits/stl_iterator_base_funcs.h:104:21: warning: array subscript is above array bounds [-Warray-bounds] return __last - __first; ~~~~~~~^~~~~~~~~ gcc-6-branch doesn't warn, but I hesitate to call this a regression because the warning is pointing out a real problem (we try to copy 2 bytes from the array "").