As covered in Does initialization entail lvalue-to-rvalue conversion? Is int x = x;
UB? the C++ standard has a surprising example in section 3.3.2
Point of declaration in which an int
is initialized with it's own indeterminate value:
int x = 12; { int x = x; }
Here the second x is initialized with its own (indeterminate) value. — end example ]
Which Johannes answer to this question indicates is undefined behavior since it requires an lvalue-to-rvalue conversion.
In the latest C++14 draft standard N3936
which can be found here this example has changed to:
unsigned char x = 12; { unsigned char x = x; }
Here the second x is initialized with its own (indeterminate) value. — end example ]
Has something changed in C++14 with respect to indeterminate values and undefined behavior that has driven this change in the example?
Yes, this change was driven by changes in the language which makes it undefined behavior if an indeterminate value is produced by an evaluation but with some exceptions for unsigned narrow characters.
Defect report 1787 whose proposed text can be found in N39141 was recently accepted in 2014 and is incorporated in the latest working draft
N3936
:The most interesting change with respect to indeterminate values would be to section
8.5
paragraph 12 which goes from:to (emphasis mine):
and included the following example:
We can find this text in N3936 which is the current working draft and
N3937
is theC++14 DIS
.Prior to C++1y
It is interesting to note that prior to this draft unlike C which has always had a well specified notion of what uses of indeterminate values were undefined C++ used the term indeterminate value without even defining it (assuming we can not borrow definition from C99) and also see defect report 616. We had to rely on the underspecified lvalue-to-rvalue conversion which in draft C++11 standard is covered in section
4.1
Lvalue-to-rvalue conversion paragraph 1 which says:Footnotes:
1787
is a revision of defect report 616, we can find that information in N3903