Promotion of enumeration with fixed underlying type
7.3.7 [conv.prom]
Ville Voutilainen

Created on 2013-01-09.00:00:00 last changed 92 months ago


Date: 2013-09-15.00:00:00

[Moved to DR at the September, 2013 meeting.]

Date: 2013-06-15.00:00:00

Proposed resolution (June, 2013):

Change [over.ics.rank] paragraph 4 as follows:

...Two conversion sequences with the same rank are indistinguishable unless one of the following rules applies:

  • A conversion that does not convert a pointer, a pointer to member, or std::nullptr_t to bool is better than one that does.

  • A conversion that promotes an enumeration whose underlying type is fixed to its underlying type is better than one that promotes to the promoted underlying type, if the two are different.

  • If class B is derived...

Date: 2013-01-09.00:00:00

According to 7.3.7 [conv.prom] paragraph 4,

A prvalue of an unscoped enumeration type whose underlying type is fixed (9.7.1 [dcl.enum]) can be converted to a prvalue of its underlying type. Moreover, if integral promotion can be applied to its underlying type, a prvalue of an unscoped enumeration type whose underlying type is fixed can also be converted to a prvalue of the promoted underlying type.

Because both of these conversions have the same rank, a call like the following is ambiguous, even though conversion to the underlying type might seem better than conversion to int:

  enum E : char { e };
  void f(char);
  void f(int);
  void g() {
    f(e);      // ambiguous

On the other hand, character types often have non-numeric semantics in programs, and programmers might use a character type just to set the size of the enumeration's object representation, not to imply character semantics for the enumeration. It might be better to leave the ambiguity in place in order to require programmers to make their intent explicit.

Date User Action Args
2014-11-24 00:00:00adminsetstatus: drwp -> c++14
2014-03-03 00:00:00adminsetstatus: dr -> drwp
2013-10-14 00:00:00adminsetmessages: + msg4681
2013-10-14 00:00:00adminsetstatus: tentatively ready -> dr
2013-09-03 00:00:00adminsetmessages: + msg4453
2013-09-03 00:00:00adminsetstatus: drafting -> tentatively ready
2013-05-03 00:00:00adminsetstatus: open -> drafting
2013-01-09 00:00:00admincreate