#include <constexpr_tag.h>
Tag type used to differentiate between constexpr
and non-constexpr
constructors. Do NOT use this feature for new classes! It should only be used to add a constexpr
constructor to an existing class in limited circumstances.
Specifically, some compilers are more likely to constant initialize global variables that have constexpr
constructors. For large non-zero objects, this can increase binary size compared to runtime initialization. Non-zero constant initialized globals are typically placed in .data
or .rodata
instead of .bss
.
Adding constexpr
to a constructor may affect existing users if their compiler constant initializes globals that were runtime initialized previously. To maintain previous behavior, add a new constexpr
constructor with ConstexprTag
instead of changing the existing constructor.
Prefer using pw::kConstexpr
to select a constexpr
-tagged constructor, rather than initializing a pw::ConstexprTag
.
constexpr
or not to control whether global variables are constant initialized. To control constant initialization, explicitly annotate global variables as constinit
/ PW_CONSTINIT
, constexpr
, or pw::RuntimeInitGlobal
. Compilers can constant initialize globals that:constinit
or constexpr
,constexpr
constructor,constexpr
actions during construction, such as calling non-constexpr
functions or placement new.