c++/7403: An ambiguity error is flagged during cast with proper perfect single match.

hkb@eastcoastpaperstock.com hkb@eastcoastpaperstock.com
Thu Jul 25 07:42:00 GMT 2002


>Number:         7403
>Category:       c++
>Synopsis:       An ambiguity error is flagged during cast with proper perfect single match.
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          rejects-legal
>Submitter-Id:   net
>Arrival-Date:   Thu Jul 25 07:16:01 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Harold K. Brown @ East Coast Paper Stock, Inc.
>Release:        g++ 2.95.4
>Organization:
>Environment:
Debian woody on Pentium III
>Description:
Second submission with corrected e-mail address!

When B y; (A)y; is invoked B:operator A() does not get selected over that of the non-matching constructors in A.
>How-To-Repeat:
compile source code with default sttings.

g++ casting_bug.cpp

Note that the file has no #'s, include files, or macros.

>Fix:
Must do the cast in the form 

A x;
B y;

(A)y;                 // does not work in this case
static_cast<A>(y);    // does not work in this case
y.operator A();       // does work in all tested cases
                      //  in this context
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: text/x-c++src; name="casting_bug.cpp"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="casting_bug.cpp"

LyoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioq
KioqKioqKioqKioqKioqKioqKgogICAgICAgICAgICAgICAgICAgICAgICAgIGNhc3RpbmdfYnVn
LmNwcCAgLSAgZGVzY3JpcHRpb24KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAtLS0tLS0t
LS0tLS0tLS0tLS0tCiAgICBiZWdpbiAgICAgICAgICAgICAgICA6IEp1bCAyNCwgMjAwMgogICAg
Y29weXJpZ2h0ICAgICAgICAgICAgOiAoQykgMjAwMiBieSBIYXJvbGQgSy4gQnJvd24KICAgIGVt
YWlsICAgICAgICAgICAgICAgIDogaGJyb3duX3VzYUB5YWhvby5jb20KICoqKioqKioqKioqKioq
KioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioq
KioqKi8KCi8qKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioq
KioqKioqKioqKioqKioqKioqKioqKioqKioKICogICAgICAgICAgICAgICAgICAgICAgICAgICAg
ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgKgogKiAgIFRoaXMg
cHJvZ3JhbSBpcyBmcmVlIHNvZnR3YXJlOyB5b3UgY2FuIHJlZGlzdHJpYnV0ZSBpdCBhbmQvb3Ig
bW9kaWZ5ICAqCiAqICAgaXQgdW5kZXIgdGhlIHRlcm1zIG9mIHRoZSBHTlUgR2VuZXJhbCBQdWJs
aWMgTGljZW5zZSBhcyBwdWJsaXNoZWQgYnkgICoKICogICB0aGUgRnJlZSBTb2Z0d2FyZSBGb3Vu
ZGF0aW9uOyBlaXRoZXIgdmVyc2lvbiAyIG9mIHRoZSBMaWNlbnNlLCBvciAgICAgKgogKiAgIChh
dCB5b3VyIG9wdGlvbikgYW55IGxhdGVyIHZlcnNpb24uICAgICAgICAgICAgICAgICAgICAgICAg
ICAgICAgICAgICAqCiAqICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg
ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICoKICoqKioqKioqKioqKioqKioqKioqKioq
KioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKi8KCi8v
IFRleHQgaW5sY3VkZWQgdW5kZXIgZmFpciB1c2UgdGhhdCBhcmUgY29weSByaWdodGVkIGJ5IG90
aGVycyBpcyBub3QKLy8gY292ZXJlZCBieSB0aGUgR05VIHRlcm1zIGFuZCBjb25kaXRpb25zLgoK
Ci8vIFRoaXMgaXMgYW4gZXhhbXBsZSBvZiBhIHBvdGVudGlhbCBnY2MgYnVnCgoKLy8gRmFjdHM6
Ci8vICAgICAgICAgKDEpIFRoZSBj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