[cfe-dev] static const POD object
rjmccall at apple.com
Mon Feb 18 13:02:00 PST 2013
On Feb 18, 2013, at 8:21 AM, Dmitri Gribenko <gribozavr at gmail.com> wrote:
> On Mon, Feb 18, 2013 at 6:13 PM, zapadinsky <zapadinsky at gmail.com> wrote:
>>>> [...] if the object is of const-qualified
>>>> type, the underlying class type shall have a user-declared default
>>>> constructor. [...]
>>> This requires a user-declared default constructor in this case.
>> Judy Ward suggestion was "It should be made clear that this paragraph does
>> not apply to static objects."
>> His suggestion was to allow instantiate a zero initialized static const
>> object. It was marked as resolved by adding "Otherwise, if no initializer is
>> specified for a non-static object..." So the authors of the standard either
>> did not understand his idea or I am right and clang shouldn't issue an error
>> on this code.
> Now I see -- current text does not reflect his intention. He might
> have intended to change the whole paragraph, but he only changed the
> second sentence.
Actually, her proposal does not appear to have survived in C++11:
To default-initialize an object of type T means:
• if T is a (possibly cv-qualified) class type (Clause 9), the default constructor for T is called (and the initialization is ill-formed if T has no accessible default constructor);
• if T is an array type, each element is default-initialized;
• otherwise, no initialization is performed.
If a program calls for the default initialization of an object of a const-qualified type T, T shall be a class type with a user-provided default constructor.
Anyway, "static" doesn't mean what you think it means in this context; it would more naturally be interpreted as "object with static storage duration".
We can weaken this restriction in MS compatibility mode, but I don't otherwise think this is a compiler defect.
More information about the cfe-dev