Movatterモバイル変換


[0]ホーム

URL:


Issue 1288 - WG21 CWG Issues
Title
Reference list initialization
Status
cd3
Section
9.5.5 [dcl.init.list]
Submitter
Daniel Krügler

Created on2011-04-06.00:00:00 last changed143 months ago

Messages

msg4009 (view)
Date: 2012-02-15.00:00:00

[Voted into the WP at the February, 2012 meeting;moved to DR at the October, 2012 meeting.]

msg3819 (view)
Date: 2011-08-15.00:00:00

Proposed resolution (August, 2011):

Change 9.5.5 [dcl.init.list] paragraph 3 as follows:

  • ...

  • Otherwise, ifT is a class type, constructors areconsidered...

  • Otherwise, ifT is a reference type, a prvaluetemporary of the type referenced byT is list-initialized,and the reference is bound to that temporary. [Note: As usual,the binding will fail and the program is ill-formed if the referencetype is an lvalue reference to a non-const type. —endnote] [Example: ... —endexample]

  • Otherwise, if the initializer list has a single elementoftypeE and eitherT is not a reference type or itsreferenced type is reference-related toE, the objector reference is initialized from that element; if a narrowingconversion (see below) is required to convert the element toT, the program is ill-formed. [Example:...

  • Otherwise, ifT is a reference type, a prvaluetemporary of the type referenced byT is list-initialized,and the reference is bound to that temporary. [Note: As usual,the binding will fail and the program is ill-formed if the referencetype is an lvalue reference to a non-const type. —endnote] [Example: ... —endexample]

  • Otherwise, if the initializer list has no elements...

  • ...

msg3472 (view)
Date: 2012-09-24.00:00:00

One might expect that in an example like

  int i;  int & ir{i};

ir would bind directly toi. However, accordingto 9.5.5 [dcl.init.list] paragraph 3, this example creates atemporary of typeint and binds the reference to thattemporary:

  • ...

  • Otherwise, ifT is a reference type, a prvaluetemporary of the type referenced byT is list-initialized,and the reference is bound to that temporary...

  • Otherwise, if the initializer list has a single element, theobject or reference is initialized from that element...

Also, the “or reference” in the last bullet is deadcode, as a reference initialization is always handled by the precedingbullet.

History
DateUserActionArgs
2014-03-03 00:00:00adminsetstatus: drwp -> cd3
2012-11-03 00:00:00adminsetstatus: dr -> drwp
2012-09-24 00:00:00adminsetmessages: +msg4009
2012-02-27 00:00:00adminsetmessages: +msg3819
2012-02-27 00:00:00adminsetstatus: ready -> dr
2011-04-06 00:00:00admincreate

[8]ページ先頭

©2009-2025 Movatter.jp