GCC Newspaper
JUNE 15, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
cobol

Cobol: Add assertion to prevent false array-bounds warning.

An assertion was added to symfind.cc to avoid a false positive from -Warray-bounds when compiling COBOL code with std::vector.

An assertion has been added to symfind.cc to ensure that the ancestors vector is not empty before accessing its last element. This change addresses a false positive from the -Warray-bounds compiler warning, which incorrectly assumed the vector was empty, leading to a warning when back() was called. This does not change functionality, only avoids a spurious warning.

In Details

This commit modifies gcc/cobol/symfind.cc. The COBOL compiler's symbol_find function experienced a false positive from -Warray-bounds due to assumptions about std::vector state. Adding _GLIBCXX_ASSERTIONS also avoids the warning, suggesting an interaction with the standard library's debug mode although the commit adds an explicit assertion instead.

For Context

The COBOL compiler within GCC sometimes produces warnings about potential array access errors, even when the code is correct. These are called "false positives." This commit adds a check to ensure that a specific array (a std::vector named ancestors) is not empty before trying to access its last element. This prevents the compiler from incorrectly flagging this line of code as a potential error, improving the developer experience without altering the compiled program's behavior.

Filed Under: cobolwarningarray-boundsbugfix