Incorrect (ambiguous) overload resolution when converting initializer list to array
| Bugzilla Link | 40098 |
| Version | trunk |
| OS | Linux |
| CC | @DougGregor,@riccibruno,@zygoloid |
Extended Description
Consider the following code:
struct S {
S(int i=1) {}
} s1, s2;
int f(S (&&r)[2]) { return 100; }
int f(S (&&r)[3]) { return 200; }
int main() {
int g = f({s1, s2});
// assert(g == 100);
}
According to [over.ics.rank]/3.1.2: "List-initialization sequence L1 is a better conversion sequence than list-initialization sequence L2 if:
- ...
- L1 converts to type “array of N1 T”, L2 converts to type “array of N2 T”, and N1 is smaller than N2"
I.e., the correct behaviour is to call the first overload. Instead Clang rejects the code because it considers the call ambiguous.
@llvm/issue-subscribers-clang-frontend
Author: Mikhail Maltsev (miyuki)
Extended Description
Consider the following code:
struct S {
S(int i=1) {}
} s1, s2;
int f(S (&&r)[2]) { return 100; }
int f(S (&&r)[3]) { return 200; }
int main() {
int g = f({s1, s2});
// assert(g == 100);
}
According to [over.ics.rank]/3.1.2: "List-initialization sequence L1 is a better conversion sequence than list-initialization sequence L2 if:
- ...
- L1 converts to type “array of N1 T”, L2 converts to type “array of N2 T”, and N1 is smaller than N2"
I.e., the correct behaviour is to call the first overload. Instead Clang rejects the code because it considers the call ambiguous.
fixed: https://godbolt.org/z/ojqYv798W