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

daniel.kruegler at googlemail dot com gcc-bugzilla@gcc.gnu.org
Tue Aug 28 13:43:00 GMT 2012


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

--- Comment #3 from Daniel Krügler <daniel.kruegler at googlemail dot com> 2012-08-28 13:43:42 UTC ---
(In reply to comment #2)
> The fix is to remove the constexpr from array::at, which isn't required by the
> standard anyway:

It's not required, but I would like to encourage you to keep it if possible,
because otherwise it would like as if the constexpr extension paper 

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2011/n3304.html

would have no implementation experience. Here is my suggested replacement
instead (based on comma operator semantics):

Replace

    return __n < _Nm ? 
           _M_instance[__n] : throw out_of_range(__N("array::at"));

by

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

This should work, because the right argument of comma operator determines type
and value category



More information about the Gcc-bugs mailing list