[cfe-dev] Suggestion for array bounds warning
Marshall Clow
mclow.lists at gmail.com
Tue Dec 18 08:50:39 PST 2012
On Dec 18, 2012, at 8:12 AM, Marshall Clow <mclow.lists at gmail.com> wrote:
> If I write
> int arr[2];
> arr[2] = -1;
>
> I get "warning: array index 2 is past end of array".
> That's great.
>
> but if I write:
> std::array<int, 2> arr;
> arr[2] = -1;
>
> I get no warning.
> I think that "it would be nice" if clang warned in that case also.
FWIW, I just committed a change to libc++ so that:
std::array<int, 2> arr;
std::get<2>(arr) = -1;
will static_assert.
Thanks to Howard for the code review.
-- Marshall
Marshall Clow Idio Software <mailto:mclow.lists at gmail.com>
A.D. 1517: Martin Luther nails his 95 Theses to the church door and is promptly moderated down to (-1, Flamebait).
-- Yu Suzuki
More information about the cfe-dev
mailing list