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.
-
Tämä twiitti ei ole saatavilla.
-
-
Vastauksena käyttäjälle @tloch14
Why would const change the type? Wouldn't that make any const_cast UB?
1 vastaus 0 uudelleentwiittausta 0 tykkäystä -
Vastauksena käyttäjälle @Bobby_Anguelov
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.
1 vastaus 0 uudelleentwiittausta 0 tykkäystä -
Vastauksena käyttäjälle @tloch14
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?
2 vastausta 0 uudelleentwiittausta 0 tykkäystä -
Vastauksena käyttäjälle @Bobby_Anguelov
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.
2 vastausta 0 uudelleentwiittausta 0 tykkäystä -
Vastauksena käyttäjälle @tloch14
Um. Are you sure that's true?! I think it's allowed to reorder access specifier blocks but not the variables defined within said blocks. My knowledge of the standard is rusty though.
1 vastaus 0 uudelleentwiittausta 0 tykkäystä
Oof. You may be right. Now that you mentione it, I recall it mostly being related to access specifier blocks as well.
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.