https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117861
--- Comment #4 from Saada Mehdi <00120260a at gmail dot com> --- (In reply to Eric Botcazou from comment #2) > No, that's a C-like reasoning, idiomatic loops in Ada never overflow their > index and, therefore, people should never fiddle with overflow checks: I've never touched a line of C, witdhdraw your insult, right now ! The real code went like this: > for D in Bins'First..Digittype'Pred(Bins'Last) when Lasts (D) > 0 loop > List (PlaceInResult..PlaceInResult + (Lasts(D) - 1)) := Listtype'([for A > of Bins (D) (Bins (D)'First..Lasts(D)) => A]); > PlaceInResult := IndexType'Base'Val (IndexType'Base'Pos (@) + Lasts(D)); > end loop; > Lasts := [others => 0]; > PlaceInResult := List'First; PlaceinResult is IndexType, which could be Natural (in case chances are Bins'Last will never reach Indextype'Last, or Boolean, then it WILL overflow. I had to treat the last iteration separately, without increment: > if Lasts(Bins'Last) > 0 then > List (PlaceInResult..PlaceInResult + (Lasts(Bins'Last) - 1)) := > Listtype'([for A of Bins (Bins'Last) (Bins > (Bins'Last)'First..Lasts(Bins'Last)) => A]); > end if; > PlaceInResult := List'First; I know this is better... It's the radix sort. I typically want to make the code as clean and without undue tests when possible, so letting it overflow seemed elegant.