]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
cobol: Add assertion to suppress -Warray-bounds false positive [PR125404]
authorJonathan Wakely <jwakely@redhat.com>
Wed, 20 May 2026 21:24:33 +0000 (22:24 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Thu, 28 May 2026 14:37:42 +0000 (15:37 +0100)
This works around a warning from std::vector code, which seems to be
assuming that the vector is empty and therefore calling back() would be
invalid:

/home/test/src/gcc/gcc/cobol/symfind.cc:526:45: error: array subscript -1 is outside array bounds of ‘long unsigned int [1152921504606846975]’ [-Werror=array-bounds=]
  526 |                     return ancestors.back() == i01;
      |                            ~~~~~~~~~~~~~~~~~^~~~~~

Compiling with -D_GLIBCXX_ASSERTIONS also fixes the warning.

gcc/cobol/ChangeLog:

PR cobol/125404
* symfind.cc (symbol_find): Add assertion that ancestors vector
is not empty.

gcc/cobol/symfind.cc

index cefc560bf31b686e5491b55961563a106d47b2a8..84eb0166cf6448d8965808219c9f19a81ea6f422 100644 (file)
@@ -523,6 +523,7 @@ symbol_find( size_t program, std::list<const char *> names ) {
                   std::inserter(qualified, qualified.begin()),
                   [i01]( auto item ) {
                     const std::vector<size_t>& ancestors(item.second);
+                    assert(!ancestors.empty());
                     return ancestors.back() == i01;
                   } );
     items = qualified;