Created on 2023-06-01.00:00:00 last changed 18 months ago
Consider:
int f(int const(&)[]) { return 1; } // #1 int f(int const(&)[2]) { return 2; } // #2 int x = f({});
Subclause 12.2.4.2.6 [over.ics.list] paragraph 6 specifies:
Otherwise, if the parameter type is “array of N X” or “array of unknown bound of X”, if there exists an implicit conversion sequence from each element of the initializer list (and from {} in the former case if N exceeds the number of elements in the initializer list) to X, the implicit conversion sequence is the worst such implicit conversion sequence.
What is the "worst [...] implicit conversion sequence" when the initializer list is empty? Should #1 even be viable for this call, given that it's not valid to initialize an int const (&)[] from {}?
There is implementation divergence: Clang and MSVC treat #1 as being non-viable; GCC calls #1 and creates a temporary of type `int[0]` (even in -pedantic-errors mode). Should the "worst conversion sequence" over an empty set be the identity conversion, selecting #1 and then failing the parameter initialization?
History | |||
---|---|---|---|
Date | User | Action | Args |
2023-06-01 00:00:00 | admin | create |