Movatterモバイル変換


[0]ホーム

URL:


This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 119a. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2025-12-20


450. Binding a reference to const to a cv-qualified array rvalue

Section:9.5.4  [dcl.init.ref]    Status:CD1    Submitter:Steve Adamczyk    Date:16 Jan 2004

[Voted into WP at October 2005 meeting.]

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.5.4 [dcl.init.ref], you sort of end upfalling off the end of the standard's description of referencebinding. The standard says in the final bullet of paragraph 5that an array temporary should be created and copy-initializedfrom the rvalue array, which seems implausible.

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

Notes from the March 2004 meeting:

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

Proposed resolution (October, 2004):

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

    If the initializer expression is an rvalue, withT2 anarray type, and “cv1T1” isreference-compatible with “cv2T2”,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 asfollows:

    An lvalue refers to an object or function. Some rvalueexpressions — those of(possibly cv-qualified) classor array typeor cv-qualified class type —also refer to objects.



[8]ページ先頭

©2009-2026 Movatter.jp