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.
It seems to me that the two vector types are unrelated. So they may as well be struct A{}; and struct B{}; It seems that you may as well be doing: A a; B& b = (b&)a; which I believe is UB.
-
-
Why do you think that? Nothing in the vector itself changes (ptr + size) and the type pointed to also doesn't change. Just the access semantics. Afaik. I can const_cast a const int and modify it without it being UB. Right?
-
The compiler is free to reorder members within a class regardless of the order they were declared in. No implementations do (that I know of), but we aren't asking about implementations.
- Näytä vastaukset
Uusi keskustelu -
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.