This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug libstdc++/54388] std::array.at() const results in undefined behaviour
- From: "daniel.kruegler at googlemail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 28 Aug 2012 13:43:42 +0000
- Subject: [Bug libstdc++/54388] std::array.at() const results in undefined behaviour
- Auto-submitted: auto-generated
- References: <bug-54388-4@http.gcc.gnu.org/bugzilla/>
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