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


865. Initializing astd::initializer_list

Section:9.5.5  [dcl.init.list]    Status:CD2    Submitter:James Widman    Date:8 April, 2009

[Voted into WP at October, 2009 meeting.]

There are several problems with the wording of 9.5.5 [dcl.init.list] paragraph 4:

When an initializer list is implicitly converted to astd::initializer_list<E>, the object passed isconstructed as if the implementation allocated an array ofNelements of typeE, whereN is the number of elementsin the initializer list. Each element of that array is initializedwith the corresponding element of the initializer list converted toE, and thestd::initializer_list<E> object isconstructed to refer to that array. If a narrowing conversion isrequired to convert the element toE, the program isill-formed.

First, an initializer list is not an expression, so it is notappropriate to refer to “implicitly convert[ing]” it,as is done in the first sentence.

Also, the conversion of the elements of the initializer list to theelements of the array is not specified to be eithercopy-initialization or direct-initialization. If this is intended tobe viewed as an aggregate initialization, it would becopy-initialization, but that needs to be specified more clearly.

Finally, the initializer list can have nested initializer lists, sothe references to converting the element also need to be cleanedup.

Proposed resolution (July, 2009):

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

When an initializer list is implicitly converted to aAn object of typestd::initializer_list<E>is constructed from an initializer list, the objectpassed is constructed as if the implementation allocated anarray ofN elements of typeE, whereN is thenumber of elements in the initializer list. Each element of that arrayiscopy-initialized with the corresponding element of theinitializer list converted toE, and thestd::initializer_list<E> object is constructed to referto that array. If a narrowing conversion is required toconvertthe element toEinitialize any of theelements, the program is ill-formed. [Example:...



[8]ページ先頭

©2009-2026 Movatter.jp