Closed vinniefalco closed 3 years ago
Throwing an exception would be non-conforming, so the best option here is to remove the non-standard extension and add a simple assert in case a null pointer is passed.
Extension removed, thanks for the report.
Glad to help. Note that the upcoming Boost.JSON scheduled for formal review September 14-24 relies heavily on Boost.Container's memory_resource
and polymorphic_allocator
as building blocks for the discriminated union containers.
What happens if users are depending on this extension? I thought throwing an exception (and causing their app to terminate) was preferable to getting possibly undefined behavior.
The function was not correctly specified as it says (https://www.boost.org/doc/libs/1_74_0/doc/html/boost/container/pmr/polymorphic_allocator.html#idm45720956936592-bb):
Requires: r is non-null.
and the note:
Non-standard extension: if r is null m_resource is set to get_default_resource().
I think the removal will not cause much pain, as it was not clear if null was or not valid.
Oh! Great! I didn't actually notice "Requires: r is non-null." when I looked at it :)
This non-standard extension: https://github.com/boostorg/container/blob/5a52472cd00994bf1752e92c1c178a5a822a36cb/include/boost/container/pmr/polymorphic_allocator.hpp#L56
Requires Boost.JSON users to link to Boost.Container even if they are not using the default resource (which they likely will never be). It also allows programs to rely on non-standard behavior, making them more difficult to port to C++17. I believe this non-standard extension should be removed. Construction of
polymorphic_allocator
with a null memory resource should throw something likelogic_error
orinvalid_parameter
.