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

* [Bug c++/64665] Overload resolution not working with std::initializer_list<std::string> and bool
  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 ` redi at gcc dot gnu.org
  2015-01-21  2:41 ` richard-gccbugzilla at metafoo dot co.uk
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2015-01-19 12:55 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2015-01-19
     Ever confirmed|0                           |1

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Possibly a duplicate of another bug but I can't find one right now.


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

* [Bug c++/64665] Overload resolution not working with std::initializer_list<std::string> and bool
  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
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: richard-gccbugzilla at metafoo dot co.uk @ 2015-01-21  2:41 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Smith <richard-gccbugzilla at metafoo dot co.uk> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |richard-gccbugzilla@metafoo
                   |                            |.co.uk

--- Comment #2 from Richard Smith <richard-gccbugzilla at metafoo dot co.uk> ---
Per DR1467, a list-initialization sequence that initializes
std::initializer_list is always better than one that does not; I think this is
invalid.


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

* [Bug c++/64665] Overload resolution not working with std::initializer_list<std::string> and bool
  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
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: duncan.forster at mac dot com @ 2015-01-21  4:35 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Duncan Forster <duncan.forster at mac dot com> ---
(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.


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

* [Bug c++/64665] Overload resolution not working with std::initializer_list<std::string> and bool
  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
                   ` (2 preceding siblings ...)
  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
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2015-01-21  8:43 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Shouldn't we add the testcase to gcc testsuite nevertheless, or do we have this
covered in the testsuite already?


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

* [Bug c++/64665] Overload resolution not working with std::initializer_list<std::string> and bool
  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
                   ` (3 preceding siblings ...)
  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
  6 siblings, 0 replies; 8+ messages in thread
From: paolo.carlini at oracle dot com @ 2015-03-05  9:07 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Let's add a reduced testcase and close the bug.


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

* [Bug c++/64665] Overload resolution not working with std::initializer_list<std::string> and bool
  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
                   ` (4 preceding siblings ...)
  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
  6 siblings, 0 replies; 8+ messages in thread
From: paolo at gcc dot gnu.org @ 2015-03-05  9:16 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from paolo at gcc dot gnu.org <paolo at gcc dot gnu.org> ---
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


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

* [Bug c++/64665] Overload resolution not working with std::initializer_list<std::string> and bool
  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
                   ` (5 preceding siblings ...)
  2015-03-05  9:16 ` paolo at gcc dot gnu.org
@ 2015-03-05  9:22 ` paolo.carlini at oracle dot com
  6 siblings, 0 replies; 8+ messages in thread
From: paolo.carlini at oracle dot com @ 2015-03-05  9:22 UTC (permalink / raw)
  To: gcc-bugs

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

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |INVALID

--- Comment #7 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Done.


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