Created on2002-01-02.00:00:00 last changed48 months ago
[Moved to DR as N4261 at the November, 2014 meeting.]
Proposed resolution (October, 2014):
The resolution is contained in paper N4261.
Additional note, February, 2014:
Geoffrey Romer: LWG plans to resolve US 16/LWG 2118, which concernsqualification-conversion of unique_ptr for array types, by effectivelypunting the issue to core:unique_ptr<T[]> will be specifiedto be convertible tounique_ptr<U[]> only ifT(*)[]is convertible toU(*)[]. LWG and LEWG have jointly decided toadopt the same approach forshared_ptr<T[]> andshared_ptr<T[N]> in the Fundamentals TS. This will probablysubstantially raise the visibility of core issue 330, which concerns thefact that array types support only top-level qualification conversion ofthe element type, so it'd be nice if CWG could bump up the priority of thatissue.
See alsoissue 1865.
Suggested resolution:
Artem Livshits proposed a resolution :-
"I suppose if the definition of "similar" pointer types in7.3.6 [conv.qual] paragraph 4 wasrewritten like this:
it would address the problem.T1 is cv1,0 P0 cv1,1 P1 ... cv1,n-1 Pn-1 cv1,n T
and
T2 is cv1,0 P0 cv1,1 P1 ... cv1,n-1 Pn-1 cv1,n T
where Pi is either a "pointer to" or a "pointer to an array of Ni"; besidesP0 may be also a "reference to" or a "reference to an array of N0" (in thecase of P0 of T2 being a reference, P0 of T1 may be nothing).
In fact I guess Pi in this notation may be also a "pointer to member", so7.3.6 [conv.qual]/{4,5,6,7} would be nicely wrapped in oneparagraph."
Section 7.3.6 [conv.qual]covers the case of multi-level pointers, but does not appear to cover thecase of pointers to arrays of pointers.The effect is that arrays are treated differently from simple scalarvalues.
Consider for example the following code:(from the thread "Pointer to array conversion question" begun incomp.lang.c++.moderated)
int main() { double *array2D[2][3]; double * (*array2DPtr1)[3] = array2D; // Legal double * const (*array2DPtr2)[3] = array2DPtr1; // Legal double const * const (*array2DPtr3)[3] = array2DPtr2; // Illegal }and compare this code with:- int main() { double *array[2]; double * *ppd1 = array; // legal double * const *ppd2 = ppd1; // legal double const * const *ppd3 = ppd2; // certainly legal (4.4/4) }The problem appears to be that the pointed to types in example 1 areunrelated since nothing in therelevant section of the standard covers it - 7.3.6 [conv.qual]does not mention conversions of the form"cv array of N pointer to T"into"cv array of N pointer to cv T"
It appears that reinterpret_cast is the only way to perform theconversion.
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-02-18 07:47:23 | admin | set | messages: +msg6680 |
| 2017-02-06 00:00:00 | admin | set | status: drwp -> cd4 |
| 2015-05-25 00:00:00 | admin | set | status: dr -> drwp |
| 2015-04-13 00:00:00 | admin | set | messages: +msg5336 |
| 2014-11-24 00:00:00 | admin | set | status: review -> dr |
| 2014-10-13 00:00:00 | admin | set | messages: +msg5147 |
| 2014-10-13 00:00:00 | admin | set | status: drafting -> review |
| 2014-07-07 00:00:00 | admin | set | status: open -> drafting |
| 2014-03-03 00:00:00 | admin | set | messages: +msg4903 |
| 2002-01-02 00:00:00 | admin | create | |