Topic: Defect Report: built-in operator= can't assign to enums


Author: Valentin Bonnard <Bonnard.V@wanadoo.fr>
Date: 2000/10/08
Raw View
scott douglass wrote:

> This still leaves the following undesirably ambiguous,

???

quatramaran bonnard ~/C++ $ cat > bogus-ambiguity.cc

        enum E { k };
        struct T { operator E(); operator double(); };
        void f() {
            T t;
            E e;
            e = t;      // ambiguous:
        }
quatramaran bonnard ~/C++ $ g++ -c bogus-ambiguity.cc
quatramaran bonnard ~/C++ $

--

Valentin Bonnard

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]






Author: scott douglass <sdouglass@arm.com>
Date: 2000/10/03
Raw View
 [Moderator's note: this defect report has been forwarded to
 the C++ committee.  -moderator (fjh).]

It appears that in 13.6 [over.built] there is no built-in operator= that
takes a enum type on the left side -- because enum types are not arithmetic
types and there are no references to arithmetic type that can bind to an
enum.  E.g.

 enum E { k };
 E e;
 e = k;  // what built-in operator= is selected here?

Perhaps the smallest change is to split the case for built-in operator= off
from the other assignment operators and allow built-in operator= to take
enums on the left side, e.g. in 13.6/18 [over.built] change:

 >>
For every triple (L, VQ, R), where L is an arithmetic type, VQ is either
volatile or empty, and R is a promoted arithmetic type, there exist
candidate operator functions of the form

VQ L& operator=(VQ L&, R);
VQ L& operator*=(VQ L&, R);
VQ L& operator/=(VQ L&, R);
VQ L& operator+=(VQ L&, R);
VQ L& operator-=(VQ L&, R);
<<

to:

 >>
For every triple (L, VQ, R), where L is an arithmetic or enum type, VQ is
either volatile or empty, and R is a promoted arithmetic type, there exist
candidate operator functions of the form

VQ L& operator=(VQ L&, R);

For every triple (L, VQ, R), where L is an arithmetic type, VQ is either
volatile or empty, and R is a promoted arithmetic type, there exist
candidate operator functions of the form

VQ L& operator=(VQ L&, R);
VQ L& operator*=(VQ L&, R);
VQ L& operator/=(VQ L&, R);
VQ L& operator+=(VQ L&, R);
VQ L& operator-=(VQ L&, R);
<<

This still leaves the following undesirably ambiguous, but that's, perhaps,
a different defect report.

 enum E { k };
 struct T { operator E(); operator double(); };
 void f() {
     T t;
     E e;
     e = t; // ambiguous:
 }
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: wmm@fastdial.net
Date: 2000/10/03
Raw View
In article <4.3.2.7.2.20001003083313.02c649e0@mail1>,
  scott douglass <sdouglass@arm.com> wrote:
>  [Moderator's note: this defect report has been forwarded to
>  the C++ committee.  -moderator (fjh).]
>
> It appears that in 13.6 [over.built] there is no built-in operator=
that
> takes a enum type on the left side -- because enum types are not
arithmetic
> types and there are no references to arithmetic type that can bind to
an
> enum.  E.g.
>
>  enum E { k };
>  E e;
>  e = k;  // what built-in operator= is selected here?

This is described in 13.6p20.

--
William M. Miller, wmm@fastdial.net
Vignette Corporation (www.vignette.com)


Sent via Deja.com http://www.deja.com/
Before you buy.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]