Inter-Procedural Optimization and Derefinement
playingwithpointers.com
playingwithpointers.com
On the other hand the compiler maybe should rename the function when it does inter-procedural optimization on it.
A similar issue affects the C++ template compilation model used in most compilers. If template instantiations weren't merged at link time, C++ binaries would be incredibly bloated (and C++ binary size is already a problem).
Sigh. I presume this is because you can pass inline functions to callbacks, and the 6 people in the world who do
if (a == &f::foo) {do something}
want it to work no matter what?
One solution, of course, is to privatize the function you call, but still hand any code paths that escape pointers and take the address the "other" version (which is i presume what you meant)
bool g(bool b) {
if (b)
return true;
int unused = 1 / 0;
return false;
}
Shouldn't it be optimized to bool g(bool b) {
return b;
}
instead of bool g(bool b) {
return true;
} int unused = 1 / 0;
is undefined behaviour. The compiler can replace it with anything it wants. Like for instance a return true. Compilers usually (ab-)use this to remove branches.The right thing to do is to issue an error or warning, and then not make absurd assumptions about other variables. A good explanation of all this can be found here: http://c9x.me/compile/bib/ubc.pdf