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

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


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

--- Comment #8 from Daniel Krügler <daniel.kruegler at googlemail dot com> 2012-08-28 20:34:34 UTC ---
(In reply to comment #4)
> > 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];
> 
> Alternatively prevent any value evaluation at all:
> 
> return __n < _Nm ? void() : throw out_of_range(__N("array::at")),  
>  _M_instance[__n];

Upon 2nd reflection I see now that neither of my proposals should work, so
Jonathan's solution is the only correct one presented here. While looking at
5.19 p2 I checked all bullets and couldn't find a problem - until finally I saw
that the initial wording of p2 says "A conditional-expression is a core
constant expression". Well yes, a comma operator does not satisfy this. Thanks
Jonathan for your correct form - I hope we can get this in as replacement for
the current implementation.



More information about the Gcc-bugs mailing list