<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/123700>123700</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Should operands in ternary operator be allowed to have explicit copy constructor?
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Rush10233
</td>
</tr>
</table>
<pre>
I've got a very confusing output with the following test:
```c++
struct QString
{
QString()=default;
explicit QString( const QString & );
};
QString def(){
return QString{};
};
void foo( bool b, QString s )
{
auto res = b ? def() : s;
}
```
It turns out that GCC accepts this with `-std=c++17` or above; EDG and ICC always accept, and clang and MSVC always reject even with `-std=c++17` or above: https://godbolt.org/z/zhza8Krfa
The diagnostic of clang and MSVC points out that if `s` is taken, the conversion from `s` to `res` will implicitly use the copy ctor of `QString`, which is not allowed:
```c++
<source>:13:29: error: no matching constructor for initialization of 'QString'
13 | auto res = b ? def() : s;
| ^
<source>:4:14: note: explicit constructor is not a candidate
4 | explicit QString( const QString & );
| ^
<source>:3:5: note: candidate constructor not viable: requires 0 arguments, but 1 was provided
3 | QString()=default;
| ^
1 error generated.
```
Although the diagnostic sounds reasonable here, I still wonder if the standard has been made some changes since C++17 according to the behavior of GCC.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyUlc9v6zYMx_8a5UK0kC0nTg4-pElTFMMOW4fdZYu2tSlSJtHO0r9-oJ2mWR_wtgc4iCDzx0fUl7ROyXYesRLLJ7HcL_RAfYjVr0PqM5krtaiDuVSvIi9HhC4QaBgxXqAJvh2S9R2EgU4DwdlSD9QjtMG5cOY3hImE2go5PSs5P43In_iR20RxaAh-eaNofcc2JW8DwG0vX4t8I9TeYKsHR0JNBvj3ydnG0p0ZA6XbBoh8BZPn0xR2f13I7YeBwfYa_JYzIg3R32KWT59-dwHGYA20IXDOOgQHtch3t7xpynp_EtADBYiYQKg91CDU4TM5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