[Bug c++/64665] New: Overload resolution not working with std::initializer_list and bool

2015-01-19 Thread duncan.forster at mac dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64665

Bug ID: 64665
   Summary: Overload resolution not working with
std::initializer_list and bool
   Product: gcc
   Version: 4.9.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: duncan.forster at mac dot com

Created attachment 34482
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=34482&action=edit
gcc -v

Test case.

#include 
#include 

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 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 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.


[Bug c++/64665] Overload resolution not working with std::initializer_list and bool

2015-01-20 Thread duncan.forster at mac dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64665

--- Comment #3 from Duncan Forster  ---
(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.