Miscellaneous-NoAccessToGlobalsInXtorΒΆ

Avoid the use of global objects in constructors and destructors as they may not yet be initialized

Required inputs: IR

Do not read or write global objects in constructor or destructor definitions.
Example
int i = 0;                // global object
class C {
    C() { i = 10; }       // bad - writing global i
    ~C() { int* p = &i; } // bad - potentially reading global i
    void foo() { i++; }   // ok - not accessed in constructor or destructor
}

Possible Messages

Key

Text

Severity

Disabled

access_global

Avoid the use of global objects in constructors and destructors as they may not yet be initialized.

None

False

Options