STL4015 warning when compiling with jsapi.h in VS2017 /std:c++17

RESOLVED FIXED in Firefox 68

Status

()

defect
P3
normal
RESOLVED FIXED
6 months ago
Last month

People

(Reporter: qwertiest, Assigned: qwertiest)

Tracking

(Blocks 1 bug)

60 Branch
mozilla68
Points:
---
Dependency tree / graph

Firefox Tracking Flags

(firefox68 fixed)

Details

Attachments

(1 attachment)

User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:65.0) Gecko/20100101 Firefox/65.0

Steps to reproduce:

  1. Include jsapi.h header in .cpp of your choice.
  2. Compile .cpp with Visual Studio 2017 /std:c++17 /W3

Problematic line is present in the trunk as well: https://dxr.mozilla.org/mozilla-central/source/js/public/ErrorReport.h?q=JSErrorNotes&redirect_type=direct#179

Solution:

  1. Remove inheritance from std::iterator<std::input_iterator_tag, js::UniquePtr<Note>>.
  2. Add the following lines in class definition:
    using iterator_category = std::input_iterator_tag;
    using value_type = js::UniquePtr<Note>;
    using difference_type = ptrdiff_t;
    using pointer = value_type*;
    using reference = value_type&;

Note: it also appears in several non-SM headers: https://dxr.mozilla.org/mozilla-central/search?q=public+std%3A%3Aiterator

Actual results:

warning C4996: 'std::iterator<std::input_iterator_tag,mozilla::UniquePtr<JSErrorNotes::Note,JS::DeletePolicy<T>>,ptrdiff_t,_Ty *,_Ty &>::reference': 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.

Status: UNCONFIRMED → NEW
Ever confirmed: true
Priority: -- → P3
Comment on attachment 9042947 [details] [diff] [review]
bug1526245-iterator-traits.patch

Review of attachment 9042947 [details] [diff] [review]:
-----------------------------------------------------------------

Thanks for this, sorry for the delay!
Attachment #9042947 - Flags: review?(jwalden) → review+
Keywords: checkin-needed
Assignee: nobody → qwertiest

Pushed by cbrindusan@mozilla.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/b9a53cec8555
Replaced std::iterator inheritance with iterator traits definitions in JSErrorNotes (as required by C++17). r=Waldo

Keywords: checkin-needed
Status: NEW → RESOLVED
Closed: 5 months ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla68
No longer blocks: 1566181
You need to log in before you can comment on or make changes to this bug.