diff options
author | Jason Merrill <jason@redhat.com> | 2009-07-24 12:02:14 -0400 |
---|---|---|
committer | Jason Merrill <jason@gcc.gnu.org> | 2009-07-24 12:02:14 -0400 |
commit | 50ea39ffdbaf4abdfad21637f200292ee5b45b42 (patch) | |
tree | c7c67975df7d7912177f9f97794ed0ea560ea005 | |
parent | a22fb74c2266c2eb002f9464d13d09b08425fa59 (diff) | |
download | gcc-50ea39ffdbaf4abdfad21637f200292ee5b45b42.tar.gz |
Core issue 702
Core issue 702
* call.c (compare_ics): Give list-initialization of std::init_list
priority over conversion to scalar, too.
From-SVN: r150059
-rw-r--r-- | gcc/cp/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/cp/call.c | 25 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp0x/initlist23.C | 15 |
4 files changed, 35 insertions, 15 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 85178863136..6bb4a57561b 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2009-07-24 Jason Merrill <jason@redhat.com> + + Core issue 702 + * call.c (compare_ics): Give list-initialization of std::init_list + priority over conversion to scalar, too. + 2009-07-22 Jason Merrill <jason@redhat.com> * mangle.c (mangle_type_string_for_rtti): Rename to be clearer. diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 845fa568529..d396aff12fd 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -6493,6 +6493,14 @@ compare_ics (conversion *ics1, conversion *ics2) ref_conv1 = maybe_handle_ref_bind (&ics1); ref_conv2 = maybe_handle_ref_bind (&ics2); + /* List-initialization sequence L1 is a better conversion sequence than + list-initialization sequence L2 if L1 converts to + std::initializer_list<X> for some X and L2 does not. */ + if (ics1->kind == ck_list && ics2->kind != ck_list) + return 1; + if (ics2->kind == ck_list && ics1->kind != ck_list) + return -1; + /* [over.ics.rank] When comparing the basic forms of implicit conversion sequences (as @@ -6543,26 +6551,13 @@ compare_ics (conversion *ics1, conversion *ics2) conversion *t1; conversion *t2; - for (t1 = ics1; t1->kind != ck_user && t1->kind != ck_list; t1 = t1->u.next) + for (t1 = ics1; t1->kind != ck_user; t1 = t1->u.next) if (t1->kind == ck_ambig || t1->kind == ck_aggr) return 0; - for (t2 = ics2; t2->kind != ck_user && t2->kind != ck_list; t2 = t2->u.next) + for (t2 = ics2; t2->kind != ck_user; t2 = t2->u.next) if (t2->kind == ck_ambig || t2->kind == ck_aggr) return 0; - /* Conversion to std::initializer_list is better than other - user-defined conversions. */ - if (t1->kind == ck_list - || t2->kind == ck_list) - { - if (t2->kind != ck_list) - return 1; - else if (t1->kind != ck_list) - return -1; - else - return 0; - } - if (t1->cand->fn != t2->cand->fn) return 0; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index f6122c20624..ea7a034092c 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2009-07-24 Jason Merrill <jason@redhat.com> + + * g++.dg/cpp0x/initlist23.C: New. + 2009-07-24 Janus Weil <janus@gcc.gnu.org> PR fortran/40822 diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist23.C b/gcc/testsuite/g++.dg/cpp0x/initlist23.C new file mode 100644 index 00000000000..48a997fca20 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/initlist23.C @@ -0,0 +1,15 @@ +// { dg-options "-std=c++0x" } + +#include <initializer_list> + +struct A +{ + A& operator=(int i); + A& operator=(std::initializer_list<int> l) { return *this; } +}; + +int main() +{ + A a; + a = { }; +} |