public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Oliver Kullmann <O.Kullmann@Swansea.ac.uk>
To: gcc-help@gcc.gnu.org
Subject: Re: Problem with templates and operator overloading
Date: Mon, 02 Feb 2004 20:52:00 -0000	[thread overview]
Message-ID: <20040202205256.GB27828@swan.ac.uk> (raw)

> 
> 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<typename T> 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

             reply	other threads:[~2004-02-02 20:52 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-02-02 20:52 Oliver Kullmann [this message]
  -- strict thread matches above, loose matches on Subject: below --
2004-02-02 16:49 Casey Goodlett
2004-02-02 18:30 ` Eljay Love-Jensen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20040202205256.GB27828@swan.ac.uk \
    --to=o.kullmann@swansea.ac.uk \
    --cc=gcc-help@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).