This answer relates to the original question. Subsequently, the question was changed.
In principle, it is impossible to determine whether a global variable is used or needed. Constructors can have side effects, so even if global access is never available, it might still be needed.
The true story: a programmer who remains nameless has removed the βunused" global from the production application. Unfortunately, the constructor for this global allocated memory from the allocator, which is initialized at the first allocation.
As a result of deleting an unused global object, the next object created using this allocator caused the allocator to initialize. Unfortunately, the initialization was not thread safe (and was clearly documented as such) - the goal of the global was to ensure that it was initialized before any threads were created.
Let's say there were very bad consequences (with the participation of this largest client of this company - the well-known three-letter government agency) and leave it to that.
A person must decide that the global does not need to be created just because it is not used, and this can be an extremely difficult decision.
David schwartz
source share