Index: include/llvm/Support/YAMLTraits.h =================================================================== --- include/llvm/Support/YAMLTraits.h +++ include/llvm/Support/YAMLTraits.h @@ -863,8 +863,13 @@ mapOptionalWithContext(Key, Val, Ctx); } + // NB: The std::enable_if is used on the Default argument to prevent this + // argument from being used in template parameter deduction. This allows the + // default value to be specified without a cast even if it's type does not + // exactly match the type of Val. template - void mapOptional(const char *Key, T &Val, const T &Default) { + void mapOptional(const char *Key, T &Val, + const typename std::enable_if::type &Default) { EmptyContext Ctx; mapOptionalWithContext(Key, Val, Default, Ctx); } Index: unittests/Support/YAMLIOTest.cpp =================================================================== --- unittests/Support/YAMLIOTest.cpp +++ unittests/Support/YAMLIOTest.cpp @@ -823,7 +823,7 @@ io.mapRequired("f1", c.f1); io.mapRequired("f2", c.f2); io.mapRequired("f3", c.f3); - io.mapOptional("f4", c.f4, MyFlags(flagRound)); + io.mapOptional("f4", c.f4, flagRound); } }; } @@ -1327,8 +1327,8 @@ static void mapping(IO &io, TotalSeconds &secs) { MappingNormalization keys(io, secs); - io.mapOptional("hours", keys->hours, (uint32_t)0); - io.mapOptional("minutes", keys->minutes, (uint8_t)0); + io.mapOptional("hours", keys->hours, 0); + io.mapOptional("minutes", keys->minutes, 0); io.mapRequired("seconds", keys->seconds); } };