https://gcc.gnu.org/bugzilla/show_bug.cgi?id=6
Jonathan Wakely changed:
What|Removed |Added
Status|UNCONFIRMED |NEW
Last reconfirmed||2021-08-10
Ever confirmed|0 |1
--- Comment #1 from Jonathan Wakely ---
This is undefined behaviour, and should definitely warn (and UBsan should give
an error too).
The implicit conversion sequence of array-to-pointer decay followed by
derived-to-base conversion should warn. If the derived-to-base conversion is
really desired (because no pointer arithmetic will be done on the result) then
users can get a pointer to the first element of the array explicitly, so there
is no implicit decay e.g. any of these would not warn:
go([0]);
go(&*bs);
go((B*)bs);
go(std::begin(bs));
(of course the code would still have undefined behaviour due to the arithmetic
in go, but it wouldn't warn because there's no implicit decay).