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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|1                           |0
         Resolution|INVALID                     |---
             Status|RESOLVED                    |UNCONFIRMED

--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
The example at the end of the change of DR 1467:
Example:

  void f1(int);                                 // #1
  void f1(std::initializer_list<long>);         // #2
  void g1() { f1({42}); }                       // chooses #2

  void f2(std::pair<const char*, const char*>); // #3
  void f2(std::initializer_list<std::string>);  // #4
  void g2() { f2({"foo","bar"}); }              // chooses #4
—end example]

http://www.open-std.org/cwg1589 is also this one too.

Plus http://www.open-std.org/cwg2076

Note I don't think constructor of A matter, it could be a function instead,
e.g.:
#include <iostream>
#include <initializer_list>
using namespace std;

struct UdfInt {
  UdfInt(int) {}
};
void f(int)
{
    cout << "f(int)\n";
}
void f(UdfInt)
{
    cout << "f(initializer_list)\n";
}
void f(std::initializer_list<UdfInt>)
{
    cout << "f(initializer_list)\n";
}
int main() {
    f({10});
  return 0;
}

GCC prints f(initializer_list) while all the rest of the compilers print
A(int).
The big question initializer_list<UdfInt> a better conversion from
initializer_list<int> than int.
I think the answer is yes.
The example in DR 1467 shows that the conversion from initializer_list<int> to
initializer_list<long> is better than the conversion from initializer_list<int>
to int (clang implements that, ICC and MSVC do not). 

I think the language change in end of DR 1467 is what applies here the most:
even if one of the other rules in this paragraph would otherwise apply.




Also if we take:
#include <iostream>
#include <initializer_list>
#include <string>
using namespace std;


#if 0
static void f(const char*)
{
    cout << "f(const char*)\n";
}
#endif
static void f(std::string)
{
    cout << "f(std::string)\n";
}
static void f(std::initializer_list<std::string>)
{
    cout << "f(initializer_list)\n";
}
int main() {
    f({"10"});
  return 0;
}

Right now all compilers agree f(initializer_list) but once we add in f(const
char*), GCC still selects f(initializer_list) while ICC/MSVC/clang select
f(const char*). That seems a bit odd.

Reply via email to