From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3554 invoked by alias); 29 Jul 2002 07:26:02 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 3481 invoked by uid 71); 29 Jul 2002 07:26:01 -0000 Resent-Date: 29 Jul 2002 07:26:01 -0000 Resent-Message-ID: <20020729072601.3480.qmail@sources.redhat.com> Resent-From: gcc-gnats@gcc.gnu.org (GNATS Filer) Resent-To: nobody@gcc.gnu.org Resent-Cc: gcc-prs@gcc.gnu.org, gcc-bugs@gcc.gnu.org Resent-Reply-To: gcc-gnats@gcc.gnu.org, topiolli@ee.oulu.fi Received: (qmail 18101 invoked by uid 61); 29 Jul 2002 07:19:55 -0000 Message-Id: <20020729071955.18100.qmail@sources.redhat.com> Date: Mon, 29 Jul 2002 00:26:00 -0000 From: topiolli@ee.oulu.fi Reply-To: topiolli@ee.oulu.fi To: gcc-gnats@gcc.gnu.org X-Send-Pr-Version: gnatsweb-2.9.3 (1.1.1.1.2.31) Subject: c++/7428: Precedence in selecting overloaded operators X-SW-Source: 2002-07/txt/msg00754.txt.bz2 List-Id: >Number: 7428 >Category: c++ >Synopsis: Precedence in selecting overloaded operators >Confidential: no >Severity: non-critical >Priority: medium >Responsible: unassigned >State: open >Class: sw-bug >Submitter-Id: net >Arrival-Date: Mon Jul 29 00:26:00 PDT 2002 >Closed-Date: >Last-Modified: >Originator: topiolli@ee.oulu.fi >Release: g++ (GCC) 3.1.1 >Organization: >Environment: SunOS tk3 5.8 Generic_108528-15 sun4u sparc SUNW,Ultra-80 >Description: I have a template class called SmartPtr that does - guess what. Since it has a typecast operator, it can be used where a pointer to the base type is expected. Also, operator == is overloaded to allow comparison of SmartPtr instances: template SmartPtr { public: operator T* () { return _internalPtr; } operator const T* () const { return _internalPtr; } }; template bool operator== (const SmartPtr&, const SmartPtr&); The compiler chokes on this. It cannot figure out whether it should use the overloaded operator to compare SmartPtrs, or should it perhaps use the built-in operators for comparing pointers, because the SmartPtr can be casted to a pointer. The problem is easily solved by removing the overloaded operator, but in my mind the overloaded operator should be the preferred choice as it does not need typecasts. >How-To-Repeat: >Fix: >Release-Note: >Audit-Trail: >Unformatted: