[PATCH] D59142: YAMLIO: Improve template arg deduction for mapOptional
Pavel Labath via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 13 01:59:13 PDT 2019
labath updated this revision to Diff 190380.
labath added a comment.
The `static_cast` also allows explicit conversions, which I don't think we
should automatically apply here (that would be circumventing the intention of
the person who made that particular conversion explicit). I fixed that by piping
the default value through a temporary reference. That should allow the same set
of conversions as during a function call, but it is also starting to look a bit
magical.
Let me know what you think.
Repository:
rL LLVM
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D59142/new/
https://reviews.llvm.org/D59142
Files:
include/llvm/Support/YAMLTraits.h
unittests/Support/YAMLIOTest.cpp
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<NormalizedSeconds, TotalSeconds> 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);
}
};
Index: include/llvm/Support/YAMLTraits.h
===================================================================
--- include/llvm/Support/YAMLTraits.h
+++ include/llvm/Support/YAMLTraits.h
@@ -863,10 +863,11 @@
mapOptionalWithContext(Key, Val, Ctx);
}
- template <typename T>
- void mapOptional(const char *Key, T &Val, const T &Default) {
+ template <typename T, typename U>
+ void mapOptional(const char *Key, T &Val, const U &Default) {
EmptyContext Ctx;
- mapOptionalWithContext(Key, Val, Default, Ctx);
+ const T &DefaultAsT = Default; // Use only implicit conversions.
+ mapOptionalWithContext(Key, Val, DefaultAsT, Ctx);
}
template <typename T, typename Context>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D59142.190380.patch
Type: text/x-patch
Size: 1573 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190313/95a33804/attachment.bin>
More information about the llvm-commits
mailing list