Title
Binding a reference to const to a cv-qualified array rvalue
Status
cd1
Section
9.4.4 [dcl.init.ref]
Submitter
Steve Adamczyk

Created on 2004-01-16.00:00:00 last changed 189 months ago

Messages

Date: 2005-10-15.00:00:00

[Voted into WP at October 2005 meeting.]

Date: 2004-10-15.00:00:00

Proposed resolution (October, 2004):

  1. Insert a new bullet in 9.4.4 [dcl.init.ref] bullet 5.2 before sub-bullet 2 (which begins, “Otherwise, a temporary of type ‘cv1 T1’ is created...”):

    If the initializer expression is an rvalue, with T2 an array type, and “cv1 T1” is reference-compatible with “cv2 T2”, the reference is bound to the object represented by the rvalue (see 7.2.1 [basic.lval]).
  2. Change 7.2.1 [basic.lval] paragraph 2 as follows:

    An lvalue refers to an object or function. Some rvalue expressions — those of (possibly cv-qualified) class or array type or cv-qualified class type — also refer to objects.
Date: 2004-03-15.00:00:00

Notes from the March 2004 meeting:

g++ and EDG give an error. Microsoft (8.0 beta) and Sun accept the example. Our preference is to allow the direct binding (no copy). See the similar issue with class rvalues in issue 391.

Date: 2004-01-16.00:00:00

It's unclear whether the following is valid:

const int N = 10;
const int M = 20;
typedef int T;
void f(T const (&x)[N][M]){}

struct X {
	int i[10][20];
};

X g();

int main()
{
	f(g().i);
}

When you run this through 9.4.4 [dcl.init.ref], you sort of end up falling off the end of the standard's description of reference binding. The standard says in the final bullet of paragraph 5 that an array temporary should be created and copy-initialized from the rvalue array, which seems implausible.

I'm not sure what the right answer is. I think I'd be happy with allowing the binding in this case. We would have to introduce a special case like the one for class rvalues.

History
Date User Action Args
2008-10-05 00:00:00adminsetstatus: wp -> cd1
2006-04-22 00:00:00adminsetstatus: dr -> wp
2005-10-22 00:00:00adminsetmessages: + msg1281
2005-10-22 00:00:00adminsetstatus: ready -> dr
2005-05-01 00:00:00adminsetstatus: review -> ready
2004-11-07 00:00:00adminsetmessages: + msg1060
2004-11-07 00:00:00adminsetstatus: drafting -> review
2004-04-09 00:00:00adminsetmessages: + msg979
2004-04-09 00:00:00adminsetstatus: open -> drafting
2004-01-16 00:00:00admincreate