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

utf8::unchecked::iterator should not derive from std::iterator #70

Closed
totalgee opened this issue Jul 24, 2021 · 4 comments
Closed

utf8::unchecked::iterator should not derive from std::iterator #70

totalgee opened this issue Jul 24, 2021 · 4 comments

Comments

@totalgee
Copy link
Contributor

Describe the bug
When compiling on VS2019 (with C++17), there are warnings from the inheritance of std::iterator by utf8::unchecked::iterator, with the following message:

1>C:\Users\...\zep\include\zep\mcommon\utf8\unchecked.h(220,40): warning C4996: std::iterator<std::bidirectional_iterator_tag,utf8::uint32_t,ptrdiff_t,utf8::uint32_t *,utf8::uint32_t &>: warning STL4015: The std::iterator class template (used as a base class to provide typedefs) is deprecated in C++17. (The <iterator> header is NOT deprecated.) The C++ Standard has never required user-defined iterators to derive from std::iterator. To fix this warning, stop deriving from std::iterator and start providing publicly accessible typedefs named iterator_category, value_type, difference_type, pointer, and reference. Note that value_type is required to be non-const, even for constant iterators. You can define _SILENCE_CXX17_ITERATOR_BASE_CLASS_DEPRECATION_WARNING or _SILENCE_ALL_CXX17_DEPRECATION_WARNINGS to acknowledge that you have received this warning. (compiling source file ..\zep\src\buffer.cpp)

To Reproduce
Steps to reproduce the behavior:

  1. Build a project using Zep under VS2019 (compiling in C++17 mode).
  2. See warnings (not hugely serious, but should be cleaned up at some point).

Expected behavior
No warnings.

Desktop (please complete the following information):

  • OS: Windows 10 Pro
  • Version 10.0.19043
  • VS2019 version 16.8.3
@cmaughan
Copy link
Collaborator

Thanks @totalgee I'm aware of this warning, and ignoring it for now, since the fix needs a bit of work!

@totalgee
Copy link
Contributor Author

Actually, I can just comment out the inheritance from std::iterator and it seems to compile and run fine (on C++17 with VS 2022, at least). You may also define using aliases for the five things mentioned above, but it even seems to work fine without doing that (at least for the current usage of Zep...?).

@totalgee
Copy link
Contributor Author

If necessary, you also could explicitly define the using aliases for those two iterator classes in Zep (in checked.h and unchecked.h) -- but as I say, it doesn't seem to be necessary...?

public:
    using iterator_category = std::bidirectional_iterator_tag;
    using value_type = uint32_t;
    using difference_type = std::ptrdiff_t;
    using pointer = uint32_t*;
    using reference = uint32_t&;

@cmaughan
Copy link
Collaborator

138b980

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