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

Warning using "allocate" directly #579

Closed
mwinterb opened this issue Oct 8, 2017 · 3 comments
Closed

Warning using "allocate" directly #579

mwinterb opened this issue Oct 8, 2017 · 3 comments

Comments

@mwinterb
Copy link
Contributor

mwinterb commented Oct 8, 2017

MSVC's library implementers are aggressively following the deprecations from the standard library in C++17. Using their "daily" releases, this warning occurs:

fmt/format.h(850,1): warning C4996: 'std::allocator<wchar_t>::allocate': warning STL4010: Various members of std::allocator are deprecated in C++17. Use std::allocator_traits instead of accessing these members directly. You can define _SILENCE_CXX17_OLD_ALLOCATOR_MEMBERS_DEPRECATION_WARNING or _SILENCE_ALL_CXX17_DEPRECATION_WARNINGS to acknowledge that you have received this warning.
  T *new_ptr = this->allocate(new_capacity, FMT_NULL);
^
<PATH>\packages\VisualCppTools.Community.Daily.VS2017Layout.14.11.25719-Pre\lib\native\include\xmemory0(992): note: see declaration of 'std::allocator<wchar_t>::allocate'
	_CXX17_DEPRECATE_OLD_ALLOCATOR_MEMBERS _DECLSPEC_ALLOCATOR _Ty * allocate(
fmt/format.h(846): note: while compiling class template member function 'void fmt::internal::MemoryBuffer<wchar_t,500,std::allocator<wchar_t>>::grow(::size_t)'
void MemoryBuffer<T, SIZE, Allocator>::grow(std::size_t size) {
fmt/format.h(1095): note: see reference to class template instantiation 'fmt::internal::MemoryBuffer<wchar_t,500,std::allocator<wchar_t>>' being compiled
  MemoryBuffer<wchar_t, INLINE_BUFFER_SIZE> buffer_;

The fix is easy, T *new_ptr = std::allocator_traits<Allocator>::allocate(*this, new_capacity, FMT_NULL); but that breaks C++98 compat, and I don't know if a small preprocessor mess is worth it for this one case. And I also don't know if Microsoft is going to fully commit to the deprecations in official releases "soon".

For now, locally I just replace the this->allocate with the allocator_traits indirection, but that needs another change to actually work, so I'll submit a PR for that shortly.

@mwinterb
Copy link
Contributor Author

mwinterb commented Oct 8, 2017

This is obviously really low priority, especially since there's an opt-out, I just wanted there to be "visibility" for when others eventually get this warning.

mwinterb added a commit to mwinterb/fmt that referenced this issue Oct 10, 2017
If using these allocators through allocator_traits (see fmtlib#579),
compilation will fail since the hint type must be of type const void*,
not value_type*.
@vitaut
Copy link
Contributor

vitaut commented Oct 15, 2017

I don't know if a small preprocessor mess is worth it for this one case

I think it's OK since allocate is only called in one place. Could you submit a PR?

@mwinterb
Copy link
Contributor Author

I can. Do you (or anyone that may see this) know when libc++ and libstdc++ introduced allocator_traits, or should I just key off of __cplusplus for them?

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

No branches or pull requests

2 participants