Created on 2001-06-12.00:00:00 last changed 24 months ago
Rationale (October, 2004):
9.2.9.2 [dcl.type.cv] paragraph 4 already forbids modifying a const member of a POD struct. The prohibition need not be repeated in 6.8 [basic.types].
Suggested resolution:
It is recommended that 6.8 [basic.types] paragraph 3 be reworded to exclude PODs which contain (directly or indirectly) members of const-qualified type.
Following the definition in Clause 11 [class] paragraph 4 the following is a valid POD (actually a POD-struct):
struct test { const int i; };
The legality of PODs with const members is also implied by the text of 7.6.2.8 [expr.new] bullet 15.1, sub-bullet 2 and 11.9.3 [class.base.init] bullet 4.2.
6.8 [basic.types] paragraph 3 states that
For any POD type T, if two pointers to T point to distinct objects obj1 and obj2, if the value of obj1 is copied into obj2, using the memcpy library function, obj2 shall subsequently hold the same value as obj1.
[Note: this text was changed by TC1, but the essential point stays the same.]
This implies that the following is required to work:
test obj1 = { 1 }; test obj2 = { 2 }; memcpy( &obj2, &obj1, sizeof(test) );
The memcpy of course changes the value of the const member, surely something that shouldn't be allowed.
History | |||
---|---|---|---|
Date | User | Action | Args |
2022-11-20 07:54:16 | admin | set | messages: + msg7054 |
2004-11-07 00:00:00 | admin | set | messages: + msg1103 |
2004-11-07 00:00:00 | admin | set | status: open -> nad |
2001-06-12 00:00:00 | admin | create |