| ▲ | nilamo an hour ago |
| This looks like a long back and fourth, that can easily be solved by a minute or two on godbolt... |
|
| ▲ | aw1621107 an hour ago | parent | next [-] |
| > that can easily be solved by a minute or two on godbolt... Unfortunately it's not that simple when it comes to UB. If the snippet in question does in fact exhibit UB then there's no guarantee whatever Godbolt shows will generalize to other programs/versions/compilers/environments/etc. |
| |
| ▲ | nilamo an hour ago | parent [-] | | That's very funny to me. A) x is always removed. B) no, it's never removed if volatile. But neither person can prove what a compiler will actually do, despite claiming they'll always act a certain way given 5 lines of code. | | |
| ▲ | tialaramex an hour ago | parent | next [-] | | Also, at behavioural edges what you'll see on Godbolt is compiler bugs. So you learn nothing about what should happen. All popular modern C++ compilers have known bugs and while I'm sure there are C compilers with no known bugs that will be because nobody tested very hard. | |
| ▲ | saagarjha an hour ago | parent | prev [-] | | I made the weaker claim that x can be removed. This is something I could prove with compiler output but I would have to find a compiler willing to make this optimization which is not something I can guarantee. |
|
|
|
| ▲ | saagarjha an hour ago | parent | prev [-] |
| No, compilers will often choose to not optimize on UB. |