4 ms·
I don't get the reference to undefined behavior. This is an aliasing issue, which is pretty well defined. Am I missing something? Other than that: Interestin
by fefe23 4y ago
I don't get the reference to undefined behavior.
This is an aliasing issue, which is pretty well defined.
Am I missing something?
Other than that: Interesting insight!
- masklinn 4y ago> I don't get the reference to undefined behavior. > [...] > Am I missing something? `int*` and `char8_t*` aliasing is UB under strict aliasing. You can call it "an aliasing issue, which is pretty well defined". As far as the compiler is concerned it's no different than every other UB it uses for constraints inference.
- sharikous 4y agoI think the idea is that if the user had aliased *count and the string they would have got undefined behavior. So the compiler can assume they didn't and is allowed to optimize away the loop with memset.
- andi999 4y agoOr do more nefarious stuff.
- eklitzke 4y agoAliasing in the first example is well defined, so no UB in the first example. Aliasing in the second example would be undefined in the sense that the strict aliasing rules forbids the two pointer types to be aliased in the first place.