Topic: Editorial/Defect Report: Unclear wording for initializer list


Author: CornedBee<wasti.redl@gmx.net>
Date: Mon, 24 Oct 2011 06:51:17 -0700 (PDT)
Raw View
Hi,

The standard wording for overload resolution involving initializer
lists is very unclear, and recent DR resolutions have only made it
worse.

There are several issues.

1) Ranking user-defined conversion sequences: 13.3.3.2p3 bullet 2
says:
"User-defined conversion sequence U1 is a better conversion sequence
than another user-defined conversion sequence U2 if they contain the
same user-defined conversion function or constructor or aggregate
initialization and the second standard conversion sequence of U1 is
better than the second standard conversion sequence of U2."

a) The "or aggregate initialization" part was added by the resolution
of DR1079. One problem is that "the same aggregate initialization" is
not meaningful. I had to look up the defect report to understand that
this means, and even so I'm not sure. It could either mean "both
sequences are aggregate initializations from initializer lists" or
"both sequences are aggregate initializations of the same type from
initializer lists" - it depends on whether you want the following case
to be ambiguous or well-formed, calling the second function:

void f(const A&);
void f(B&&);
f({1, 2}); // assuming both A and B are aggregates compatible with
this init list

b) 13.3.3.1.5p3&  4 describe list-initialization sequences for non-
aggregate classes and aggregate classes, respectively. Both say that
"the implicit conversion sequence is a user-defined conversion
sequence", without specifying anything else. While it seems fairly
logical that, barring other circumstances (like reference binding),
the resulting user-defined conversion sequence has an identity
conversion as the second standard conversion sequence, the standard
doesn't say anything about it. This makes ranking by 13.3.3.2p3 bullet
2 unnecessarily unclear.

2) DR702 added a third bullet to 13.3.3.2p3:
"List-initialization sequence L1 is a better conversion sequence than
list-initialization sequence L2 if L1
converts to std::initializer_list<X>  for some X and L2 does not."

This is poorly formulated. List-initialization sequences are
completely specified by equivalence to other kinds of initialization
sequence. In fact, 13.3.3.1p3 defines only standard, user-defined and
ellipsis conversion sequence as valid conversion sequences. So what
this bullet really wants to says is, "when the argument is an
initializer list and the two conversion sequences are otherwise equal,
conversion to a std::initializer_list instantiation is preferred".
Again, though, it took me looking up the original defect report to
understand this.

Clang will take the following resolutions:
1a) Only initialization of the same aggregate type is distinguishable
by the second standard conversion sequence.
1b) The second standard conversion is the identity conversion unless
reference binding changes this. The first standard conversion is, if
I'm not mistaken, irrelevant.
2) As suggested.


--
[ comp.std.c++ is moderated.  To submit articles, try posting with your ]
[ newsreader.  If that fails, use mailto:std-cpp-submit@vandevoorde.com ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]




Author: =?ISO-8859-1?Q?Daniel_Kr=FCgler?=<daniel.kruegler@googlemail.com>
Date: Tue, 25 Oct 2011 09:59:01 -0700 (PDT)
Raw View
Am 24.10.2011 15:51, schrieb CornedBee:
>  Hi,
>
>  The standard wording for overload resolution involving initializer
>  lists is very unclear, and recent DR resolutions have only made it
>  worse.
>
>  There are several issues.

Forwarded to CWG.

Greetings from Bremen,

Daniel Kr   gler



--
[ comp.std.c++ is moderated.  To submit articles, try posting with your ]
[ newsreader.  If that fails, use mailto:std-cpp-submit@vandevoorde.com ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]