In my Qt5 project, I encountered the following setup:
#include <initializer_list>
struct QJsonArray;
struct QJsonValue
{
/*explicit*/ QJsonValue(QJsonArray const &) {}
};
struct QJsonArray
{
QJsonArray(QJsonArray const &) {}
QJsonArray(std::initializer_list<QJsonValue>) {}
};
void f(QJsonArray a = {})
{
QJsonArray b {a}; // GCC: init-list ; Clang: Copy-Cc
QJsonArray c (a); // GCC: Copy-Cc ; Clang: Copy-Cc
}
int main()
{
f();
}
You can see that on the commented lines that GCC and Clang disagree on what constructor should be called.
(You can test this code on C++ Compiler Explorer with latest GCC and Clang with flag -std=c++11
)
If I uncomment the explicit
, both compilers select the same constructor (the copy constructor).
Which compiler is right here?