This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 115e. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2024-11-11


884. Defining an explicitly-specialized static data member

Section: 13.9.4  [temp.expl.spec]     Status: CD2     Submitter: Daniel Krügler     Date: 29 April, 2009

[Voted into WP at October, 2009 meeting.]

13.9.4 [temp.expl.spec] paragraphs 15-16 contain the following note:

[Note: there is no syntax for the definition of a static data member of a template that requires default initialization.
    template<> X Q<int>::x;
This is a declaration regardless of whether X can be default initialized (9.4 [dcl.init]). —end note]

While this note is still accurate, the C++0x list initialization syntax provides a way around the restriction, which could be useful if the class is not copyable or movable but has a default constructor. Perhaps the note should be updated to mention that possibility?

Proposed resolution (July, 2009):

Change 13.9.4 [temp.expl.spec] paragraphs 15-16 as follows:

An explicit specialization of a static data member of a template is a definition if the declaration includes an initializer; otherwise, it is a declaration. [Note: there is no syntax for the The definition of a static data member of a template that requires default initialization. must use a braced-init-list:

  template<> X Q<int>::x;      // declaration
  template<> X Q<int>::x ();   // error: declares a function
  template<> X Q<int>::x {};   // definition

This is a declaration regardless of whether X can be default initialized (9.4 [dcl.init]).end note]