YAMLIO: Improve template arg deduction for mapOptional
Summary: The way c++ template argument deduction works, both arguments are used to deduce the template type in the three-argument overload of mapOptional. This is a problem if the types are slightly different, even if they are implicitly convertible. This is fairly easy to trigger with integral types, as the default type of most integral constants is int, which then requires casting the constant to the type of the other argument. This patch fixes that by using a separate template type for the default value, which is then cast to the type of the first argument. To avoid this conversion triggerring conversions marged as explicit, we use static_assert to check that the types are implicitly convertible. Reviewers: zturner, sammccall Subscribers: kristina, jdoerfert, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D59142 llvm-svn: 356157
Loading
Please sign in to comment