I guess I'll throw in my (unverified) observation. vector<int*> and vector<int const*> are two unrelated types, regardless of the relationship of the types they contain, and as such the cast is UB.
I guess, all that being said, I gave it a shot in godbolt with -fsanitize=undefined and it didn't return any errors. *shrug*. If it were me, I'd use a span<int const *>.
-
-
At risk of inciting a mob, those who follow
@lefticus may be best equipped to answer this. -
Yes, they are two completely unrelated types, and it is UB. Breaks strong aliasing rules. Most uses of const_cast enable UB and almost all uses of reinterpret_cast result in UB, and your c-style cast is a reinterpret_cast. I'll let
@shafikyaghmour link his articles - Näytä vastaukset
Uusi keskustelu -
-
-
Then again, -fsanitize=undefined didn't trip for this code, which looks real suspect to me.pic.twitter.com/8K1fPxmD1x
-
-Wstrict-aliasing and friends are more likely to catch this at compile time than UBSan is at runtime
Keskustelun loppu
Uusi keskustelu -
-
-
UB sanitizer is best at catching arithmetic UB, like signed integer overflow.
Kiitos. Käytämme tätä aikajanasi parantamiseen. KumoaKumoa
-
Lataaminen näyttää kestävän hetken.
Twitter saattaa olla ruuhkautunut tai ongelma on muuten hetkellinen. Yritä uudelleen tai käy Twitterin tilasivulla saadaksesi lisätietoja.