Anyone have a link to what the C++ standard says regarding a compiler removing global and static symbols? I thought you weren’t guaranteed that the compiler will remove global symbols if they’re not referenced. A colleague of mine asserts that if your global symbols are included in the main translation unit, those symbols will not be removed even if they’re not referenced.
Share
Interestingly, all I can find on this in the C++2003 standard is this:
This implies that the standard permits elimination of items in static storage if initialization and destruction of them have no side effects and they are otherwise unused.
If there’s a more direct permission, I didn’t see it (but maybe someone else will).
However, it should be noted that having the linker eliminate unused objects in the final image is a very common optimization.