[Bug libstdc++/54388] std::array.at() const results in undefined behaviour

redi at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Tue Aug 28 13:55:00 GMT 2012


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54388

--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-08-28 13:55:36 UTC ---
The paper does have implementation experience, and experience shows we got it
wrong ;)

We could do:

  return __n < _Nm ? _M_instance[__n]
         : (std::__throw out_of_range(__N("array::at")), _M_instance[0]);

and still get rid of the code that's conditionally compiled on __EXCEPTIONS.

N.B. the second branch uses _M_instance[0] to avoid possible warnings about
out-of-bounds accesses.



More information about the Gcc-bugs mailing list