Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #6429

Re: ambiguous operator on Visual Studio 2010

From "Aaron Gray" <ang.usenet@gmail.com>
Newsgroups comp.lang.c++
Subject Re: ambiguous operator on Visual Studio 2010
Date 2011-06-08 17:22 +0100
Message-ID <959lv3Fj2kU1@mid.individual.net> (permalink)
References <959al7FrddU1@mid.individual.net> <isnta6$9da$1@dont-email.me> <959dg6FhmcU1@mid.individual.net>

Show all headers | View raw


"Aaron Gray" <ang.usenet@gmail.com> wrote in message 
news:959dg6FhmcU1@mid.individual.net...
> "Victor Bazarov" <v.bazarov@comcast.invalid> wrote in message 
> news:isnta6$9da$1@dont-email.me...
>> On 6/8/2011 9:09 AM, Aaron Gray wrote:
>>> I am getting an ambiguous operator error in VS2010 but not in GCC 4.5.
>>>
>>> The following code illustrates the problem :-
>>>
>>>
>>> enum flags { OK, TEST };
>>>
>>> inline bool operator >= (flags f1, flags f2) {
>>> return (f1 & f2) == f2;
>>> }
>>>
>>> int main(int argc, char *argv[]) {
>>> flags f1 = OK;
>>> flags f2 = TEST;
>>> bool b = f1 >= f2;
>>> return 0;
>>> }
>>>
>>>
>>> gives the following on VS2010 :-
>>>
>>> 1> test.cpp
>>> 1>c:\test\c++\operator-test\operator-test\test.cpp(10): error C2593:
>>> 'operator >=' is ambiguous
>>> 1> c:\test\c++\operator-test\operator-test\test.cpp(3): could be 'bool
>>> operator >=(flags,flags)'
>>> 1> or 'built-in C++ operator>=(flags, flags)'
>>> 1> while trying to match the argument list '(flags, flags)'
>>>
>>> What is the correct ISO C++ 2004 behaviour ?
>>
>> The correct behavior is to call the user-defined operator.
>>
>> Seems like a bug in the compiler that can't make the correct choice 
>> between a user-defined function with each argument's matching exactly and 
>> the built-in operator that requires a conversion (integral promotion).  I 
>> say, report it.  Comeau gets it right as well.
>>
>> I believe the Visual C++ creators missed the fact that in order for the 
>> compiler to use >= with enumeration, the integral promotion [conv.prom] 
>> should be performed (see [expr.rel]/2), and according to [over.ics.scs]/3 
>> an exact match (for identity category) has a higher rank than a 
>> promotion. A clear bug.
>
> Right !

Yep  ! :-

http://connect.microsoft.com/VisualStudio/feedback/details/529700/enum-operator-overloading-broken

Aaron

Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

ambiguous operator on Visual Studio 2010 "Aaron Gray" <ang.usenet@gmail.com> - 2011-06-08 14:09 +0100
  Re: ambiguous operator on Visual Studio 2010 Victor Bazarov <v.bazarov@comcast.invalid> - 2011-06-08 09:26 -0400
    Re: ambiguous operator on Visual Studio 2010 "Aaron Gray" <ang.usenet@gmail.com> - 2011-06-08 14:58 +0100
      Re: ambiguous operator on Visual Studio 2010 "Aaron Gray" <ang.usenet@gmail.com> - 2011-06-08 17:22 +0100
        Re: ambiguous operator on Visual Studio 2010 "Balog Pal" <pasa@lib.hu> - 2011-06-08 18:47 +0200
          Re: ambiguous operator on Visual Studio 2010 Krice <paulkp@mbnet.fi> - 2011-06-08 11:40 -0700
          Re: ambiguous operator on Visual Studio 2010 "Bo Persson" <bop@gmb.dk> - 2011-06-08 21:29 +0200
            Re: ambiguous operator on Visual Studio 2010 "Alf P. Steinbach /Usenet" <alf.p.steinbach+usenet@gmail.com> - 2011-06-08 21:50 +0200
              Re: ambiguous operator on Visual Studio 2010 Öö Tiib <ootiib@hot.ee> - 2011-06-08 16:06 -0700
                Re: ambiguous operator on Visual Studio 2010 "Alf P. Steinbach /Usenet" <alf.p.steinbach+usenet@gmail.com> - 2011-06-09 03:20 +0200
                Re: ambiguous operator on Visual Studio 2010 Krice <paulkp@mbnet.fi> - 2011-06-09 03:00 -0700
                Re: ambiguous operator on Visual Studio 2010 "Alf P. Steinbach /Usenet" <alf.p.steinbach+usenet@gmail.com> - 2011-06-09 20:46 +0200
                Re: ambiguous operator on Visual Studio 2010 Krice <paulkp@mbnet.fi> - 2011-06-09 23:08 -0700
                Re: ambiguous operator on Visual Studio 2010 Öö Tiib <ootiib@hot.ee> - 2011-06-10 02:33 -0700
                Re: ambiguous operator on Visual Studio 2010 "Alf P. Steinbach /Usenet" <alf.p.steinbach+usenet@gmail.com> - 2011-06-10 12:26 +0200
                Re: ambiguous operator on Visual Studio 2010 Öö Tiib <ootiib@hot.ee> - 2011-06-09 04:52 -0700
                Re: ambiguous operator on Visual Studio 2010 "Alf P. Steinbach /Usenet" <alf.p.steinbach+usenet@gmail.com> - 2011-06-09 20:51 +0200
                Re: ambiguous operator on Visual Studio 2010 Öö Tiib <ootiib@hot.ee> - 2011-06-10 01:58 -0700
                Re: ambiguous operator on Visual Studio 2010 "Alf P. Steinbach /Usenet" <alf.p.steinbach+usenet@gmail.com> - 2011-06-10 12:36 +0200
            Re: ambiguous operator on Visual Studio 2010 "Balog Pal" <pasa@lib.hu> - 2011-06-09 13:32 +0200
          Re: ambiguous operator on Visual Studio 2010 "Balog Pal" <pasa@lib.hu> - 2011-06-10 12:24 +0200

csiph-web