Issue 123700
Summary Should operands in ternary operator be allowed to have explicit copy constructor?
Labels new issue
Assignees
Reporter Rush10233
    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.

_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to