<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/92813>92813</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
In copy-list-initialization, if an explicit constructor is chosen, the initialization is ill-formed and the diagnostic should be reported.
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang:diagnostics
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
romanova-ekaterina
</td>
</tr>
</table>
<pre>
Consider the following testcase (see below).
According to 13.3.1.7 Initialization by list-initialization is C++11 standard
"In copy-list-initialization, if an explicit constructor is chosen, the initialization is ill-formed."
However, clang doesn't report an error.
```
#include <initializer_list>
class AAA {
public:
AAA(int,int,int) {
}
};
class BBB {
int value;
public:
BBB() : value(10) {
}
BBB(const AAA& ) : value(20) {
}
explicit BBB(int,int,int) : value(33) {
}
int get_value() {
return value;
}
};
int test_function (void) {
BBB b({10,13,17}); // Diagnostic message should be reported here?
return 1;
}
int main() {
test_function();
}
```
Clang doesn't report any diagnostic for it.
Microsoft's cl compiler (version 19) complains about it:
```
cl /c test.cpp /all
Microsoft (R) C/C++ Optimizing Compiler Version 19.29.30154 for x86
Copyright (C) Microsoft Corporation. All rights reserved.
cl : Command line warning D9002 : ignoring unknown option '/all'
test.cpp
test.cpp(26): error C2664: 'BBB::BBB(BBB &&)': cannot convert argument 1 from 'initializer list' to 'BBB &&'
test.cpp(26): note: copy-list-initialization of 'BBB' cannot use an explicit constructor
test.cpp(17): note: see declaration of 'BBB::BBB'
```
Older gcc compiler (gcc 10.2.0) also complains about it:
```
$ gcc -c test.cpp -Wall
test.cpp: In function ‘int test_function()’:
test.cpp:26:21: error: call of overloaded ‘BBB(<brace-enclosed initializer list>)’ is ambiguous
26 | BBB b({10,13,17}); // Diagnostic message should be reported here?
| ^
test.cpp:14:5: note: candidate: ‘BBB::BBB(const AAA&)’
14 | BBB(const AAA& ) : value(20) {
| ^~~
test.cpp:8:7: note: candidate: ‘constexpr BBB::BBB(const BBB&)’
8 | class BBB {
| ^~~
test.cpp:8:7: note: candidate: ‘constexpr BBB::BBB(BBB&&)’
test.cpp:26:9: warning: unused variable ‘b’ [-Wunused-variable]
26 | BBB b({10,13,17}); // Diagnostic message should be reported here?
| ^
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzEV89v27gS_mvoy8CCRNqWdfDBkhO8Hh4KvMPrsaCosc0tTQok5TQ99G9fkJIt2U7a7gLbDQLFsma-75vh_FC4c_KgETdkWZLlbsY7fzR2Y82Ja3Pmc_zCPVqp-aw2zeumMtrJBi34I8LeKGVepD6AR-cFdwiErh0i1KjMC6FFQtIdSbf9dSuEsU00N5CxhCVZksMHLb3kSn7jXhoN9Sso6fxc3n4tHVSEloSWWQbOc91w2wzglH7QIEz7On_Dk9AK5B64BvzaKimkB2G087YT3tiAK47GYbQLMT3ySqXme2NP2CSE0p7zP-YFz2iDk1BcH6Ax6DShuQeLrbE-Elpr7E0GyCodfgflTGqhugaBsOrKjPZzCISwp95MKO4cbLdbIHnZf9V2tZKCsAEXAMJzQtdSe0KrybUYnYIVyXcDd74jrJyK62nKsrz1kNrDmasOr-ZvkJdlSeg6srHtYE7XWfoD_jvfeCh9ECu4B6K_BHQ94B7xrVRMMBn7FcwQ_QH954tX8BmdSFpY9J3Vdxn6SaYDaOiYz_tOi1hmhK7PRjYPisJp1IE2L0Myq4yFSx4gaUFYCYQ-E_oMO8kP2jgvBZzQOX5AcEfTqQZqHCoSGziiRcKeR_hBfDbqu81AEHriUl_ONi9hdL6JoLd4A-eu4uO1eq9lXqEZA9mH9vQJTD3_K4U1zuw9obkDoUCYUysV2phBtC4kMyuC2PBEcakd8Np0HqS_VuydKKFCGkUMKBFtG-64UneMgeF_Abgi9HmYRfCx9fIkv4WZVl2U_P8qI6FFwtJsuYixfF2vhvBN-2rl4RghqwA5klTGtsbG2ZMAbJWCaOnAokN7DjPopmVjSVfmdOK6ASU1wgu3O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