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.
  • [Bug libstdc++/98518] N... arnaud02 at users dot sourceforge.net via Gcc-bugs

Reply via email to