[PATCH] D32251: Implement DR1601 - Promotion of enumeration with fixed underlying type
Richard Smith via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 19 17:53:02 PDT 2017
rsmith added inline comments.
================
Comment at: lib/Sema/SemaOverload.cpp:3850-3853
// In Microsoft mode, prefer an integral conversion to a
// floating-to-integral conversion if the integral conversion
// is between types of the same size.
// For example:
----------------
This should probably go after all the standard orderings.
================
Comment at: lib/Sema/SemaOverload.cpp:3872
+ // promoted underlying type, if the two are different.
+ if (S.getLangOpts().CPlusPlus11 &&
+ (SCS1.getToType(1).getTypePtr() != SCS2.getToType(1).getTypePtr())) {
----------------
I don't think it makes sense to condition this on C++11 mode: we support fixed underlying types for enums in C++98 as an extension, and they should get this behavior too.
================
Comment at: lib/Sema/SemaOverload.cpp:3874-3879
+ bool S1ConvResult = isEnumConversionToUnderlyingType(S.Context, SCS1);
+ bool S2ConvResult = isEnumConversionToUnderlyingType(S.Context, SCS2);
+ if (S1ConvResult && !S2ConvResult)
+ return ImplicitConversionSequence::Better;
+ else if (!S1ConvResult && S2ConvResult)
+ return ImplicitConversionSequence::Worse;
----------------
This does not check that the "other" conversion converts to the promoted underlying type. It looks like this would (incorrectly) also order a case like:
```
enum A : char { a };
void f(char);
void f(const char&);
void g() { f(a); }
```
https://reviews.llvm.org/D32251
More information about the cfe-commits
mailing list