What's the rule on static template member initialization?

Are compilers allowed to optimize these out if they are not referenced? Seems different to normal static members, which alsays initialize.

https://wandbox.org/permlink/gaZzUiVVVpdCOBnJ
> Are compilers allowed to optimize these out if they are not referenced?

Unless there is an explicit instantiation, implementations are required to optimise these out if they are not referenced.

Unless a member of a class template or a member template has been explicitly instantiated or explicitly specialized, the specialization of the member is implicitly instantiated when the specialization is referenced in a context that requires the member definition to exist or if the existence of the definition of the member affects the semantics of the program; in particular, the initialization (and any associated side effects) of a static data member does not occur unless the static data member is itself used in a way that requires the definition of the static data member to exist.
http://eel.is/c++draft/temp.inst
Topic archived. No new replies allowed.