Closed Bug 1526245 Opened 5 years ago Closed 5 years ago

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

Categories

(Core :: JavaScript Engine, defect, P3)

60 Branch
defect

Tracking

()

RESOLVED FIXED
mozilla68
Tracking Status
firefox68 --- fixed

People

(Reporter: qwertiest, Assigned: qwertiest)

References

Details

Attachments

(1 file)

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 years 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.

Attachment

General

Creator:
Created:
Updated:
Size: