That sort of optimization can only be done by the linker. For example there could be a bar.obj that uses the foobar class, in which case it should not be discarded.