From 0ee3f0a892918371a5245de973480bc443126558 Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Sun, 16 Sep 2007 17:26:42 +0000 Subject: [PATCH] re PR c++/32756 (wrong ambiguous overload error?) cp/ PR c++/32756 * call.c (maybe_handle_implicit_object): Set this_p, clear rvaluedness_matches_p. (compare_ics): Do not compare rvaluedness matching when one of the operands is an implicit object. testsuite/ PR c++/32756 * g++.dg/overload/operator3.C: New. From-SVN: r128528 --- gcc/cp/ChangeLog | 13 ++++++++++ gcc/cp/call.c | 26 +++++++++++-------- gcc/testsuite/ChangeLog | 5 ++++ gcc/testsuite/g++.dg/overload/operator3.C | 31 +++++++++++++++++++++++ 4 files changed, 64 insertions(+), 11 deletions(-) create mode 100644 gcc/testsuite/g++.dg/overload/operator3.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 26028a520c1..6e8a8b9e5b9 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,16 @@ +2007-09-16 Nathan Sidwell + + cp/ + PR c++/32756 + * call.c (maybe_handle_implicit_object): Set this_p, clear + rvaluedness_matches_p. + (compare_ics): Do not compare rvaluedness matching when one of the + operands is an implicit object. + + testsuite/ + PR c++/32756 + * g++.dg/overload/operator3.C: New. + 2007-09-14 Jason Merrill PR c++/17743, c++/19163 diff --git a/gcc/cp/call.c b/gcc/cp/call.c index dd41b9d8168..dc90d1952e1 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -5767,7 +5767,8 @@ maybe_handle_implicit_object (conversion **ics) t = t->u.next; t = build_identity_conv (TREE_TYPE (t->type), NULL_TREE); t = direct_reference_binding (reference_type, t); - t->rvaluedness_matches_p = 1; + t->this_p = 1; + t->rvaluedness_matches_p = 0; *ics = t; } } @@ -6126,18 +6127,21 @@ compare_ics (conversion *ics1, conversion *ics2) initialized by S2 refers is more cv-qualified than the type to which the reference initialized by S1 refers */ - if (ref_conv1 && ref_conv2 - && same_type_ignoring_top_level_qualifiers_p (to_type1, to_type2)) + if (ref_conv1 && ref_conv2) { - if (ref_conv1->rvaluedness_matches_p - && !ref_conv2->rvaluedness_matches_p) - return 1; - else if (!ref_conv1->rvaluedness_matches_p - && ref_conv2->rvaluedness_matches_p) - return -1; + if (!ref_conv1->this_p && !ref_conv2->this_p + && (TYPE_REF_IS_RVALUE (ref_conv1->type) + != TYPE_REF_IS_RVALUE (ref_conv2->type))) + { + if (ref_conv1->rvaluedness_matches_p) + return 1; + if (ref_conv2->rvaluedness_matches_p) + return -1; + } - return comp_cv_qualification (TREE_TYPE (ref_conv2->type), - TREE_TYPE (ref_conv1->type)); + if (same_type_ignoring_top_level_qualifiers_p (to_type1, to_type2)) + return comp_cv_qualification (TREE_TYPE (ref_conv2->type), + TREE_TYPE (ref_conv1->type)); } /* Neither conversion sequence is better than the other. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 0721c01858e..d99cdad1941 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2007-09-16 Nathan Sidwell + + PR c++/32756 + * g++.dg/overload/operator3.C: New. + 2007-09-16 Richard Sandiford * gcc.target/mips/truncate-1.c: New test. diff --git a/gcc/testsuite/g++.dg/overload/operator3.C b/gcc/testsuite/g++.dg/overload/operator3.C new file mode 100644 index 00000000000..ff56967886e --- /dev/null +++ b/gcc/testsuite/g++.dg/overload/operator3.C @@ -0,0 +1,31 @@ +// PR c++/32756 +// { dg-do compile } + +// bogus overload warning + +class QString; + +struct QByteArray +{ + QByteArray (); + bool operator!= (const QString & s2) const; +}; + +bool operator!= (const QByteArray & a1, const QByteArray & a2); + +struct QString +{ + QString (); + QString (const QByteArray & a); +}; + +QByteArray abbreviation (); + +void +fromString () +{ + QByteArray zoneAbbrev; + if (abbreviation () != zoneAbbrev) + { + } +} -- 2.30.2