[Bug libstdc++/98518] New: std::array not bound checked with _GLIBCXX_ASSERTIONS

arnaud02 at users dot sourceforge.net gcc-bugzilla@gcc.gnu.org
Mon Jan 4 21:34:51 GMT 2021


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

            Bug ID: 98518
           Summary: std::array not bound checked with _GLIBCXX_ASSERTIONS
           Product: gcc
           Version: 10.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: arnaud02 at users dot sourceforge.net
  Target Milestone: ---

operator[] of std::array is not bound checked when specifying
_GLIBCXX_ASSERTIONS.

Considering:
#define _GLIBCXX_ASSERTIONS 1
#include <array>
#include <cstdio>
int f(int i) {
  std::array<int,2> x = {1, 4};
  return x[i]; // bounds are not checked  
}
int main() {
  volatile int i = 2;
  printf("f=%d\n", f(i));
}

the array bound violation is not detected. By constrast, replacing std::array
by std::vector results in the expected assertion violation.


More information about the Gcc-bugs mailing list