On 14.03.2016 02:09, Chris Vine wrote:
> On 14 Mar 2016 00:49:09 GMT
>
r...@zedat.fu-berlin.de (Stefan Ram) wrote:
>> I might have asked a similar question already. But maybe
>> there was no answer or maybe I still do not understand it.
>>
>> A specification for C++ says:
>>
>> »(8.1) --- if T is a (possibly cv-qualified) class type
>> (Clause 9) with either no default constructor (12.1) or
>> a default constructor that is user-provided or deleted,
>> then the object is default-initialized;«
>
> This is not in §8.1 of any C++ standard I have looked at. What version
> are you quoting?
It's C++14 or later. N3936 was the last working draft before C++14. The
wording was introduced in the resolution of [1]defect report 1301 “Value
initialization of union” – it's the definition of value initialization.
Recall that Andrew Koenig proposed value initialization for C++03, in
order to get rid of quite counter-intuitive behavior for default
initialization (or not) of aggregates in C++98. It was the only new
thing in C++03, which otherwise was just a collection of bug fixes, the
Technical Corrigendum 1, TC1. And to some degree also value
initialization might be considered a bug fix.
So this all started out as at least partially a bug fix, but the fix was
weird enough to yield unanticipated undesirable effects with the rules
of C++11, which caused additional bug fixes in C++14. And MAYBE the
wording makes some kind of technical sense. But in my humble opinion
they just fucked up, because that wording does not make sense to an
ordinary reader, even one well versed in C++ standardese.
> You also seem to have incorrectly pasted the text
> because if the default constructor is deleted then I cannot see how an
> object could be default initialized at all.
The text is correctly pasted. And apparently it's got something to do
with value initialization of a union. But I agree, it's really nonsense,
they bungled it.
There's also other nonsense in C++14, e.g. support for premature
micro-optimizations of allocations, where a sequence of small
allocations can be changed into a single one. Just a complication of
things, addressing internal implementation details. It reads like a
first year student of not particularly high ability has got access to
define the C++ standard.
I think the committee must have ceased working as a real standards body
as of C++14.
> You may need to repost the text in question.
C++14 (as of the N3936 draft) §8.5/8
To value-initialize an object of type T means:
— if T is a (possibly cv-qualified) class type (Clause 9) with either no
default constructor (12.1) or a default constructor that is
user-provided or deleted, then the object is default-initialized;
— if T is a (possibly cv-qualified) class type without a user-provided
or deleted default constructor, then the object is zero-initialized and
the semantic constraints for default-initialization are checked, and if
T has a non-trivial default constructor, the object is default-initialized;
— if T is an array type, then each element is value-initialized;
— otherwise, the object is zero-initialized.
Cheers & hth.,
- Alf
Notes:
[1] <url:
http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1301>