Created on 2016-04-29.00:00:00 last changed 83 months ago
Rationale (July, 2017):
CWG determined that the existing wording is correct: the result of the comparison is implementation-defined, but not unspecified, so the program is well-formed but the assertion is not guaranteed to pass.
According to 7.6.10 [expr.eq] bullet 2.1,
Comparing pointers is defined as follows:
If one pointer represents the address of a complete object, and another pointer represents the address one past the last element of a different complete object87, the result of the comparison is unspecified.
The use of the term “complete object” is confusing. A complete object is one that is not a subobject of any other object (6.7.2 [intro.object] paragraph 2), so this restriction apparently does not apply to non-static data members. Is the following guaranteed to work?
struct S { int i[2]; int j[2]; }; constexpr bool check1() { S s = { { 1, 2 }, { 3, 4 } }; return &s.i[2] == &s.j[0]; } static_assert(check1(), "Guaranteed?");
In particular, is there a guarantee that there is no padding between nonstatic data members of the same type?
History | |||
---|---|---|---|
Date | User | Action | Args |
2018-02-27 00:00:00 | admin | set | messages: + msg6008 |
2016-04-29 00:00:00 | admin | create |