Created attachment 34482 [details] gcc -v Test case. #include <string> #include <iostream> void Test1(const bool arg) { std::cout << "Right[" << arg << "] (standard conversion sequence)" << std::endl; } void Test1(const std::string arg) { std::cout << "Wrong[" << arg.size() << "] (user-defined conversion sequence)" << std::endl; } void Test2(const int arg) { std::cout << "Wrong[" << arg << "] (no conversion, doesn't initializes std::initializer_list)" << std::endl; } void Test2(const std::initializer_list<int> arg) { std::cout << "Right[" << arg.size() << "] (no conversion, initializes std::initializer_list)" << std::endl; } struct S { S(int _a) : a(_a){} int getA() const { return a; } private: int a; }; void Test3(const int arg) { std::cout << "Right[" << arg << "] (standard conversion sequence)" << std::endl; } void Test3(const S arg) { std::cout << "Wrong[" << arg.getA() << "] (user-defined conversion sequence)" << std::endl; } void Test4(const bool arg) { std::cout << "Right[" << arg << "] (standard conversion sequence)" << std::endl; } void Test4(const std::initializer_list<std::string> arg) { std::cout << "Wrong[" << arg.size() << "] (user-defined conversion sequence)" << std::endl; } int main (int /*argc*/, char * const /*argv*/[]) { Test1({"false"}); Test2({123}); Test3({456}); Test4({"false"}); return 0; } GCC should print: Right[1] (standard conversion sequence) Right[1] (no conversion, initializes std::initializer_list) Right[456] (standard conversion sequence) Right[1] (standard conversion sequence) GCC prints this instead: Right[1] (standard conversion sequence) Right[1] (no conversion, initializes std::initializer_list) Right[456] (standard conversion sequence) Wrong[1] (user-defined conversion sequence) Here are the two conversion sequences for Test4: {const char[6]} -> {const char*} -> {bool} (standard conversion sequence) {const char[6]} -> {const char*} -> {std::string::ctor} (user-defined conversion sequence) The standard conversion sequence should be preferred over a user-defined conversion sequence.
Possibly a duplicate of another bug but I can't find one right now.
Per DR1467, a list-initialization sequence that initializes std::initializer_list is always better than one that does not; I think this is invalid.
(In reply to Richard Smith from comment #2) I've been back and forth about what is correct behavior , in the end I think you're correct. GCC seems to be doing the right thing according to the latest C++ defect reports.
Shouldn't we add the testcase to gcc testsuite nevertheless, or do we have this covered in the testsuite already?
Let's add a reduced testcase and close the bug.
Author: paolo Date: Thu Mar 5 09:15:58 2015 New Revision: 221207 URL: https://gcc.gnu.org/viewcvs?rev=221207&root=gcc&view=rev Log: 2015-03-05 Paolo Carlini <paolo.carlini@oracle.com> PR c++/64665 * g++.dg/cpp0x/initlist92.C: New. Added: trunk/gcc/testsuite/g++.dg/cpp0x/initlist92.C Modified: trunk/gcc/testsuite/ChangeLog
Done.