range checks in DynamicConverter
Summary: Add range-checking to convertTo for small numeric types. Internally, dynamics represent a numeric with an int64_t or a double. When converting to a smaller numeric type, DynamicConverter uses a static_cast. This causes some confusion (re D936940). The code now uses folly::to, which throws a std::range_error on overflow. While working on this I also added some light comments to the new toDynamic section, for consistency with the original convertTo commenting. I also renamed the internal trait is_associative_container to is_map, since is_associative_container is looking for a mapped_type typedef and hence excludes such associative containers as sets. While adding the overflow tests, I also augmented the typetraits test to include the is_map and is_range traits, which hitherto had no test coverage. Test Plan: build and run tests, both in dbg and opt Reviewed By: cberner@fb.com FB internal diff: D961605
Showing
Please register or sign in to comment