Title
auto with braced-init-list
Status
cd2
Section
9.2.9.6 [dcl.spec.auto]
Submitter
Jason Merrill

Created on 2008-08-27.00:00:00 last changed 143 months ago

Messages

Date: 2009-07-15.00:00:00

[Voted into WP at July, 2009 meeting.]

Date: 2009-03-15.00:00:00

Proposed resolution (March, 2009):

Change 9.2.9.6 [dcl.spec.auto] paragraph 3 as follows:

...The decl-specifier-seq shall be followed by one or more init-declarators, each of which shall have a non-empty initializer. of either of the following forms:
    = assignment-expression
    ( assignment-expression )

[Drafting note: This change does not address the original issue of the inability to use auto with an array initializer, only the secondary issue of permitted the braced-init-list. The CWG explicitly decided not to support the array case.]

Date: 2008-08-27.00:00:00

One effect of the initializer-list proposal is that now we allow

    auto x = { 1, 2, 3 };  // decltype(x) is std::initializer_list<int>

but not

    auto ar[3] = { 1, 2, 3 };  // ill-formed

This seems unfortunate, as the code for the first could also support the second. Incidentally, I also failed to update the text in 9.2.9.6 [dcl.spec.auto] paragraph 3 which forbids the use of auto with braced-init-lists, so technically the first form above is currently ill-formed but has defined semantics.

Bjarne Stroustrup:

Is this the thin edge of a wedge? How about

    vector<auto> v = { 1, 2, 3 };

and

    template<class T> void f(vector<T>& v);
    f({1, 2, 3 });

(See also issue 625.)

History
Date User Action Args
2010-03-29 00:00:00adminsetstatus: wp -> cd2
2009-11-08 00:00:00adminsetstatus: dr -> wp
2009-08-03 00:00:00adminsetmessages: + msg2255
2009-08-03 00:00:00adminsetstatus: ready -> dr
2009-03-23 00:00:00adminsetmessages: + msg1886
2009-03-23 00:00:00adminsetstatus: open -> ready
2008-08-27 00:00:00admincreate