Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Direct use of Allocator::allocate is deprecated in C++17 #67

Closed
uecasm opened this issue Jun 17, 2019 · 5 comments
Closed

Direct use of Allocator::allocate is deprecated in C++17 #67

uecasm opened this issue Jun 17, 2019 · 5 comments

Comments

@uecasm
Copy link

uecasm commented Jun 17, 2019

#ifdef _RWSTD_NO_CLASS_PARTIAL_SPEC
void *vd_ptr = alloc_.allocate(sz, is_allocated_? eback() : 0);
Ch *new_ptr = static_cast<Ch *>(vd_ptr);
#else
Ch *new_ptr = alloc_.allocate(sz, is_allocated_? eback() : 0);
#endif

Should use allocator_traits when at least C++11 is detected instead; the above code produces a deprecation warning in some compiler configurations.

There might be some other code that should be updated as well, but this was the only one that I noticed a warning being flagged on (when compiling with VS2017 in C++17 mode).

@bansan85
Copy link

Right. LibreOffice uses the following patch :

-newptr = alloc_.allocate(new_size, is_allocated_? oldptr : 0);
+newptr = std::allocator_traits<compat_allocator_type>::allocate(alloc_, new_size, is_allocated_? oldptr : 0);

@jwakely
Copy link

jwakely commented Mar 30, 2020

The issue title is misleading: only the two argument form of std::allocator<T>::allocate is deprecated (i.e. the form taking a 'hint' argument). And that form has not been required for user-defined allocators since C++11: allocators are only required to provide allocate(size_type n), so portable use of a hint has required going via allocator_traits<Alloc>::allocate for almost a decade.

Using allocator_traits directly is necessary to portably pass a hint, but it would also be possible to just stop passing a hint argument. Do any real allocators make use of the hint?

@uecasm
Copy link
Author

uecasm commented Mar 30, 2020

While that's true, as noted in the original description at least MSVC's STL does generate a deprecation warning on direct calls to std::allocator::allocate, which is how I noticed this in the first place. Or it's that std::allocator<void> itself is entirely deprecated.

Related, there are also no calls to construct/destroy, which do have to go through allocator_traits. They're guaranteed no-ops for std::allocator and all standard char types, but might possibly be interesting for a non-standard allocator. Probably not a big deal though.

It also doesn't follow the allocator propagation rules and doesn't have a allocator instance constructor, which might be a bigger deal. As such it doesn't qualify as an AllocatorAwareContainer -- which it wouldn't anyway since it's not a Container, but it's almost one.

@jwakely
Copy link

jwakely commented Mar 30, 2020

Yeah, this code looks like it takes an allocator argument, but only actually works when that argument is std::allocator, so it might as well not bother pretending to support allocators at all. Oh well.

@glenfe
Copy link
Member

glenfe commented May 26, 2020

Resolved in 5884c3d.

@glenfe glenfe closed this as completed May 26, 2020
doronbehar added a commit to doronbehar/nixpkgs that referenced this issue Mar 12, 2021
gnss-sdr needs it: boostorg/format#67 .
uhd and gnuradio need to use the same boost version to avoid
incompatibilities issues. icu is needed from some reason with boost17x.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants