Re: [hub] Andrzej's review
Peter Dimov via Boost <[email protected]>
| Newsgroups | gmane.comp.lib.boost.devel |
|---|---|
| Message-ID | <[email protected]> |
> Andrzej Krzemienski wrote: > > 5. Compiling with -Wall gives me a warning in GCC when sorting an > > empty > > hub: a zero-sized heap array is allocated: > > https://godbolt.org/z/dWvxv9n8s > > This is technically fine to allocate such arrays, but maybe it is > > worth to make -Wall clean. > > The warning isn't caused by the zero sized allocation (which is legal.) > > It's because the compiler can see that the array has zero elements, but can't > see that the loop inside this call to visit > > https://github.com/joaquintides/hub/blob/063cf1d3589d4893b53964084ee > 56f4476eed471/include/boost/container/hub.hpp#L1628 > > is never executed. So it says "if this loop is executed, it would be UB because > there aren't any elements there" but this is a false positive because the loop > isn't executed. > > (The subsequent loops suffer from the same issue and also cause warnings for > the same reason.) > > A common problem with GCC, and unfortunately nothing can be done about it > short of disabling the warning. On second thought, given that the warning only fires on empty containers, it might be possible to avoid if `sort` checks for `empty()` (or `size() <= 1`) and returns. Adding a branch to avoid a warning is a bit dubious in general, but in this case it avoids a completely unnecessary allocation as well, so it's sound even in principle. :-) _______________________________________________ Boost mailing list -- [email protected] To unsubscribe send an email to [email protected] https://lists.boost.org/mailman3/lists/boost.lists.boost.org/ Archived at: https://lists.boost.org/archives/list/[email protected]/message/RCE73B2JCZXITG37467NZUNGGPZ6R2SQ/