This is an archive of the discontinued LLVM Phabricator instance.

[libc++] [API BREAK] Change `fs::path::iterator::iterator_category` to `input_iterator_tag`.
ClosedPublic

Authored by Quuxplusone on Jan 1 2022, 5:02 PM.

Details

Summary

This essentially reverts e02ed1c255d71 and puts in a new fix, which makes path::iterator a true C++20 bidirectional_iterator, but downgrades it to an input_iterator in C++17.

Fixes https://github.com/llvm/llvm-project/issues/37852

However, notice that this makes *it do a copy (of a hopefully short string), rather than just returning a reference; that might have perf implications.
And notice that a for-loop like for (auto& elt : path) will no longer compile (but this is just more evidence that auto&& Always Works ;)).
On the plus side, after this patch there is no downside to using std::reverse_iterator<fs::path::iterator>... unless I've missed something.

Diff Detail

Event Timeline

Quuxplusone requested review of this revision.Jan 1 2022, 5:02 PM
Quuxplusone created this revision.
Herald added 1 blocking reviewer(s): Restricted Project. · View Herald TranscriptJan 1 2022, 5:02 PM

I am fine with this, but it needs a release note under API changes. Also, it's technically possible for this to be an ABI break (if someone had path::iterator::reference in their ABI). However, if they do, it would cause a mangling issue so it would be caught at compile-time, which makes this acceptable to me ABI-wise.

Before I really give this a ship-it, let me run it on a large code base. We might discover some interesting fallout.

libcxx/test/std/input.output/filesystems/class.path/path.itr/iterator.pass.cpp
35
Quuxplusone marked an inline comment as done.

@ldionne ping!

Note to self: 87400598.

I'll ping this again in a couple of days once I have more information.

ldionne accepted this revision.Jan 17 2022, 9:44 AM

Built a significant codebase and didn't see any issues. It doesn't mean that it won't cause *any* issues at all in the wild (I'm sure it will bite at least a few people), but at this point I don't see anything serious enough to prevent us from shipping this bugfix.

libcxx/docs/ReleaseNotes.rst
109
This revision is now accepted and ready to land.Jan 17 2022, 9:44 AM
libcxx/docs/ReleaseNotes.rst
109

Before this patch, it was rejected in C++17 and C++20 (and C++14, if you used std::__fs::filesystem::path::iterator to get at it).
After this patch, it is rejected in neither C++17 nor C++20.
(Ah, you thought it would be rejected in C++17 because path::iterator is an input iterator, not a bidirectional iterator, in C++17? Well, C++17 reverse_iterator doesn't care what your iterator category is. :) In C++17, it has an operator-- that DTRT, so it works.)

libcxx/include/__iterator/reverse_iterator.h