Title
[tiny] Allow conversion from pointer to array of known bound to pointer to array of unknown bound
Status
open
Section
[conv]
Submitter
Richard Smith

Created on 2014-02-15.00:00:00 last changed 131 months ago

Messages

Date: 2014-07-01.21:57:43

With core issue 393, we're allowing function parameters to have type 'T (*)[]' or 'T (&)[]'. This has always been allowed for variables, and is useful in practice:

// guaranteed to be passed an actual array, not just a pointer, but the array can be of any size.
void f(int n, int (&a)[]) {
  ... do stuff with first n elements of a ...
}

extern int arr[];
void g() { f(100, arr); }
void h(int *p) { f(100, p); } // error, not an array!

// elsewhere
int arr[100]; // ok, no problem
void i() { f(100, arr); } // error!

Note that if you actually know the bound of 'arr', you *cannot* pass it to f, because you can't pass 'int [100]' glvalues to a 'int (&)[]' parameter.

So, I'd like EWG to consider this extension:

We should allow "array of N T" glvalues to convert to "array of unknown bound of T", and likewise we should allow "cv pointer to array of N T" prvalues to convert to "cv pointer to array of unknown bound of T" prvalues.

Discussed in Rapperswil 2014. EWG wishes to encourage Smith to write a paper for EWG review, EWG expects to send it forwards to CWG without much ado.

History
Date User Action Args
2014-02-15 00:00:00admincreate