https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124618
--- Comment #2 from Andrea Agostini <andrea.agostini.sax at gmail dot com> ---
(In reply to Andrew Pinski from comment #1)
> The problem is dealing with std::launder.
>
>
> Add a simple help in data to say that >8 for size before the launder gets
> rid of the warning. That is:
> ```
> int* data() noexcept
> {
> if (size_ > 8) __builtin_unreachable();
> return std::launder(reinterpret_cast<int*>(storage_));
> }
> ```
>
> This should help code in general anyways ...
Thank you for your suggestion. I have to say, though, `data()` is an awfully
counterintuitive location for a size check. I would would instantly question
such code.
While it's clear that `std::launder` is a trigger for this warning, I know of
other workarounds that make it somewhat apparent that something is wrong with
the for-loops length computation. Any of the following makes the warning go
away:
a) give each for-loop an explicit lower bound: `std::size_t i = 0` for the
first one and `std::size_t i = min_size` for the other two;
b) insert `i = min_size;` between the first and second for-loop;
c) wrape the second and third for-loops in an
`if (old_size < new_size) { ... } else { ... }`