From -7207443753602922843
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,c8441b0648a55331,start
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 2002-01-02 22:11:20 PST
Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!news1.optus.net.au!optus!news.mel.connect.com.au!news.unimelb.edu.au!bounce-back
From: "Roger Orr" <rogero@howzatt.demon.co.uk>
Newsgroups: comp.std.c++
Subject: Defect Report: pointer to array qualification conversions
Date: 03 Jan 02 06:10:51 GMT
Organization: OR/2 Limited
Lines: 68
Approved: Fergus Henderson <fjh@cs.mu.oz.au>
Message-ID: <1010015542.7310.0.nnrp-14.9e98aa01@news.demon.co.uk>
NNTP-Posting-Host: mundook.cs.mu.oz.au
X-Trace: ariel.ucs.unimelb.edu.au 1010038271 26628 128.250.29.16 (3 Jan 2002 06:11:11 GMT)
X-Complaints-To: news@news.unimelb.edu.au
NNTP-Posting-Date: 3 Jan 2002 06:11:11 GMT
X-Original-Date: Wed, 2 Jan 2002 23:38:37 -0000
X-Newsreader: Microsoft Outlook Express 4.71.1712.3
X-MimeOLE: Produced By Microsoft MimeOLE V4.71.1712.3
X-Auth: PGPMoose V1.1 PGP comp.std.c++
	iQBFAgUAPDP18+EDnX0m9pzZAQH8kAF8CoUkLeH3Duo8BM9tt+xM4xtWAMbZnTsS
	OCr7RZrXrIGgMjR1AzL9Qu9ouNzjkWqs
	=tiV+
Xref: archiver1.google.com comp.std.c++:8762

	[Moderator's note: this defect report has been
	forwarded to the C++ committee. -moderator.]

Section 4.4 "Qualification Conversions" [conv.qual]
covers the case of multi-level pointers, but does not appear to cover the
case of pointers to arrays of pointers.
The effect is that arrays are treated differently from simple scalar values.

Consider for example the following code:
(from the thread "Pointer to array conversion question" begun in
comp.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 are
unrelated since nothing in the
relevant section of the standard covers it - 4.4 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 the conversion.

Artem Livshits proposed a resolution :-

"I suppose if the definition of "similar" pointer types in 4.4/4 was
rewritten like this:

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"; besides
P0 may be also a "reference to" or a "reference to an array of N0" (in the
case of P0 of T2 being a reference, P0 of T1 may be nothing).

it would address the problem.

In fact I guess Pi in this notation may be also a "pointer to member", so
4.4/{4,5,6,7} would be nicely wrapped in one paragraph."

Roger Orr
--
MVP in C++ at www.brainbench.com
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]


