From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16016 invoked by alias); 2 Feb 2004 20:52:59 -0000 Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org Received: (qmail 16005 invoked from network); 2 Feb 2004 20:52:57 -0000 Received: from unknown (HELO mhs.swan.ac.uk) (137.44.1.33) by sources.redhat.com with SMTP; 2 Feb 2004 20:52:57 -0000 Received: from cs-svr1.swan.ac.uk ([137.44.2.59]) by mhs.swan.ac.uk with esmtp (Exim 4.30) id 1Anl3w-00022n-KZ; Mon, 02 Feb 2004 20:52:56 +0000 Received: from cs-svr1.swan.ac.uk (localhost [127.0.0.1]) by cs-svr1.swan.ac.uk (8.12.7/8.12.7/SuSE Linux 0.6) with ESMTP id i12Kqu4b007193; Mon, 2 Feb 2004 20:52:56 GMT Received: (from csoliver@localhost) by cs-svr1.swan.ac.uk (8.12.7/8.12.7/Submit) id i12KquWB007192; Mon, 2 Feb 2004 20:52:56 GMT Date: Mon, 02 Feb 2004 20:52:00 -0000 From: Oliver Kullmann To: gcc-help@gcc.gnu.org Subject: Re: Problem with templates and operator overloading Message-ID: <20040202205256.GB27828@swan.ac.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4i X-SA-Exim-Mail-From: O.Kullmann@swansea.ac.uk X-SW-Source: 2004-02/txt/msg00016.txt.bz2 > > I'm having trouble with the following piece of c++ code. Is this a bug > in gcc or am I doing something wrong? The code compiles and runs > without problems in icc. > > GCC Version: 3.3.2 > > struct doubler { > double operator*(double val) { > return 2.0 * val; > } > }; > > template T operator*(double lhs , T rhs) { > return rhs * lhs; > } > > int main() { > doubler a; > a * 3.0; > return 0; > } > > Compiling this gives the following error message. > > test3.cc: In function `T operator*(double, T)': > test3.cc:7: error: `T operator*(double, T) [with T = double]' must have > an > argument of class or enumerated type > > Thanks. > I can't find no fault with this code: When overload resolution happens (section 13.3 of the Standard), then according to clause 13.3.1.2 the set of member candidates for operator * consists of doubler::operator *(double), while the set of non-member candidates is empty. So overload resolution should unambiguously choose the member operator of class doubler. Instead, gcc seems to ignore the member operator, and considers as only candidate the operator template, resulting in a failing overload resolution. To me g++ seems to be wrong. Oliver