From the answer of this question I came across a rather interesting phenomenon. Given the following two functions:
void require(void * volatile) { }
template <typename T>
void requireT(T * volatile) { }
Calling each with a pointer to a static data member will enforce that member to be instantiated (which was the purpose of the other question), however, requireT
will be optimized away completely, while require
has an impact on the resulting code/binary (g++ 4.9.2).
Why is this? What difference is there in how the compiler treats the code?