public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/64665] New: Overload resolution not working with std::initializer_list<std::string> and bool
@ 2015-01-19 11:16 duncan.forster at mac dot com
  2015-01-19 12:55 ` [Bug c++/64665] " redi at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: duncan.forster at mac dot com @ 2015-01-19 11:16 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64665

            Bug ID: 64665
           Summary: Overload resolution not working with
                    std::initializer_list<std::string> 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 <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.


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2015-03-05  9:22 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-19 11:16 [Bug c++/64665] New: Overload resolution not working with std::initializer_list<std::string> and bool duncan.forster at mac dot com
2015-01-19 12:55 ` [Bug c++/64665] " redi at gcc dot gnu.org
2015-01-21  2:41 ` richard-gccbugzilla at metafoo dot co.uk
2015-01-21  4:35 ` duncan.forster at mac dot com
2015-01-21  8:43 ` jakub at gcc dot gnu.org
2015-03-05  9:07 ` paolo.carlini at oracle dot com
2015-03-05  9:16 ` paolo at gcc dot gnu.org
2015-03-05  9:22 ` paolo.carlini at oracle dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).