Qt-NonPodGlobalStatic

Global statics shall be trivially default constructible and trivially destructible

Required inputs: IR

Constructors of globals are run before main, on library load, slowing down startup. This is more a problem for libraries, since usually the app won't use every feature the library provides, so it's a waste of resources to call constructors from unused features.

It is tolerated to have global statics in executables, so it is the user's job to run this rule only on libraries. It doesn't harm, though, to also remove global statics from executables, because they're usually evil.

The same goes for destructors at library unload time. A good way to fix them is by using Q_GLOBAL_STATIC.

[1] The term 'POD' is too strict. The correct term is 'types with a trivial dtor and trivial ctor', and that's how this check is implemented.

This rule is based on clazy rule non-pod-global-static

Possible Messages

Key

Text

Severity

Disabled

non_pod_global_static

Non-POD global static variable.

None

False

Options

level

level : int = 1

Importance level of the rule as given for clazy. 0 is most desirable, higher values fall off in quality.
 

macro_name_whitelist

macro_name_whitelist : list[str] = ['Q_COREAPP_STARTUP_FUNCTION']

Global variables resulting from invocations of these macros are ignored.