PR c++/92032 - DR 1601: Promotion of enum with fixed underlying type.
authorMarek Polacek <polacek@redhat.com>
Wed, 9 Oct 2019 17:49:26 +0000 (17:49 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Wed, 9 Oct 2019 17:49:26 +0000 (17:49 +0000)
commite295e3d981355c61b72eca2ee58864958655cc31
treed1b8598399fa993a898daaad3a2f9c7df5232162
parentcb57504a550158913258e5be8ddb991376475efb
PR c++/92032 - DR 1601: Promotion of enum with fixed underlying type.

I've been messing with compare_ics recently and noticed that we don't
implement CWG 1601, which should be fairly easy.  Thus this patch.

The motivating example is
  enum E : char { e };
  void f(char);
  void f(int);
  void g() {
    f(e);
  }
where the call to f was ambiguous but we should choose f(char).

Currently we give f(int) cr_promotion in standard_conversion, while
f(char) remains cr_std, which is worse than cr_promotion.  So I thought
I'd give it cr_promotion also and then add a tiebreaker to compare_ics.

* call.c (standard_conversion): When converting an enumeration with
a fixed underlying type to the underlying type, give it the cr_promotion
rank.
(compare_ics): Implement a tiebreaker as per CWG 1601.

* g++.dg/cpp0x/scoped_enum10.C: New test.
* g++.dg/cpp0x/scoped_enum11.C: New test.

From-SVN: r276766
gcc/cp/ChangeLog
gcc/cp/call.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/scoped_enum10.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp0x/scoped_enum11.C [new file with mode: 0644]