Created on 2006-01-30.00:00:00 last changed 178 months ago
[Voted into the WP at the March, 2009 meeting.]
Proposed resolution (June, 2008):
Add the following note at the end of 7.6.19 [expr.ass] paragraph 8:
If the value being stored in an object is accessed from another object that overlaps in any way the storage of the first object, then the overlap shall be exact and the two objects shall have the same type, otherwise the behavior is undefined. [Note: This restriction applies to the relationship between the left and right sides of the assignment operation; it is not a statement about how the target of the assignment may be aliased in general. See 7.2.1 [basic.lval]. —end note]
Notes from the October, 2006 meeting:
This issue is based on a misunderstanding of the intent of the wording in 7.6.19 [expr.ass] paragraph 8. Instead of being a general statement about aliasing, it's describing the situation in which the source of the value being assigned is storage that overlaps the storage of the target object. The proposed resolution should make that clearer rather than changing the specification.
There appear to be two different specifications for when aliasing is permitted. One is in 7.2.1 [basic.lval] paragraph 15:
If a program attempts to access the stored value of an object through an lvalue of other than one of the following types the behavior is undefined
the dynamic type of the object,
a cv-qualified version of the dynamic type of the object,
a type similar (as defined in 7.3.6 [conv.qual]) to the dynamic type of the object,
a type that is the signed or unsigned type corresponding to the dynamic type of the object,
a type that is the signed or unsigned type corresponding to a cv-qualified version of the dynamic type of the object,
an aggregate or union type that includes one of the aforementioned types among its members (including, recursively, a member of a subaggregate or contained union),
a type that is a (possibly cv-qualified) base class type of the dynamic type of the object,
a char or unsigned char type.
There is also a much more restrictive specification in 7.6.19 [expr.ass] paragraph 8:
If the value being stored in an object is accessed from another object that overlaps in any way the storage of the first object, then the overlap shall be exact and the two objects shall have the same type, otherwise the behavior is undefined.
This affects, for example, the definedness of operations on union members: when may a value be stored into one union member and accessed via another.
It should be noted that this conflict existed in C90 and is unchanged in C99 (see, for example, section 6.5 paragraph 7 and section 6.5.16.1 paragraph 3 of ISO/IEC 9899:1999, which directly parallel the sections cited above).
History | |||
---|---|---|---|
Date | User | Action | Args |
2010-03-29 00:00:00 | admin | set | status: wp -> cd2 |
2009-08-03 00:00:00 | admin | set | status: dr -> wp |
2009-03-23 00:00:00 | admin | set | messages: + msg2020 |
2009-03-23 00:00:00 | admin | set | status: ready -> dr |
2008-10-05 00:00:00 | admin | set | status: review -> ready |
2008-06-29 00:00:00 | admin | set | messages: + msg1692 |
2008-06-29 00:00:00 | admin | set | status: drafting -> review |
2006-11-05 00:00:00 | admin | set | messages: + msg1414 |
2006-04-22 00:00:00 | admin | set | status: open -> drafting |
2006-01-30 00:00:00 | admin | create |