C++ Logo

liaison

Advanced search

Re: [wg14/wg21 liaison] (SC22WG14.19262) C memory object model study group - uninitialised reads and padding

From: Jens Maurer <Jens.Maurer_at_[hidden]>
Date: Wed, 14 Apr 2021 23:16:58 +0200
On 14/04/2021 23.06, Uecker, Martin wrote:
> I wonder why C++ made the change to inderminate values in C++14?
> (As I understand it, this is where it diverged from C).
> This seems to cause a lot of trouble now and, quite frankly,
> I do not see a real benefit in C++'s rules for indeterminate
> values that are worth all the trouble.

The change towards "indeterminate value" is more a specification
clarification than an actual semantics change.

In C++11, we had in the section talking about lvalue-to-rvalue
conversion (i.e. reading a scalar value from memory):

"If the object to which the glvalue refers is not [...], or if
the object is uninitialized, a program that necessitates this
conversion has undefined behavior."

Questions arose whether that would also apply to bytes,
and how that would interact with a user-written memcpy
look-alike, and whether the property "uninitialized"
was retained even after an assignment to that object.

The introduction of "indeterminate value" formalized
the behavior in this area.

Jens

Received on 2021-04-14 16:17:10