This is an archive of the discontinued LLVM Phabricator instance.

[libc++] Add _LIBCPP_ABI_NO_ITERATOR_BASES. Fix input/output iterators' difference_type for C++20.
AbandonedPublic

Authored by Quuxplusone on May 25 2021, 10:36 AM.

Details

Reviewers
Mordante
cjdb
ldionne
zoecarver
Group Reviewers
Restricted Project
Summary

This makes ostream_iterator and ostreambuf_iterator conforming to C++20, I think. (They needed to be default-constructible. But p2325 will remove the default constructor again, as a DR against C++20, when it lands.)

Supersedes D101729.

Diff Detail

Event Timeline

Quuxplusone requested review of this revision.May 25 2021, 10:36 AM
Quuxplusone created this revision.
Herald added 1 blocking reviewer(s): Restricted Project. · View Herald TranscriptMay 25 2021, 10:36 AM
cjdb requested changes to this revision.May 25 2021, 10:41 AM
cjdb added inline comments.
libcxx/include/iterator
620–626

This is already taken care of in D101729. It's literally the point of that patch. Same anywhere else you're doing this.

This revision now requires changes to proceed.May 25 2021, 10:41 AM

WDYT about/would it be possible to add a test that would fail if we had an ABI break, but doesn't because we don't break ABI with this change (so long as we're not using the unstable ABI)?

libcxx/include/__config
97

Are there some docs we can stick this in? Maybe mention it's enabled by default for the unstable ABI (as it should be).

ldionne requested changes to this revision.May 25 2021, 2:04 PM
ldionne added inline comments.
libcxx/include/iterator
792

There is no ABI implication here AFAICT, since the first member will always begin at offset 0 anyway. So this means this can just be #if _LIBCPP_STD_VER <= 14.

Also, notice that your _LIBCPP_STD_VER is wrong, it should be compared to 14, not 11. The std::iterator bases were removed in C++17.

915

Same.

983

Same.

1027

Same.

1104

Same.

Quuxplusone added inline comments.
libcxx/include/iterator
792

The ABI implication is the existence of the empty base (see https://quuxplusone.github.io/blog/2021/05/07/std-iterator-as-a-base-class/ ). For example,

#include <vector>
#include <iterator>
#include <stdio.h>
struct S : std::back_insert_iterator<std::vector<int>>, std::iterator<std::output_iterator_tag, void, void, void, void> {};
int main() { printf("%d\n", (int)sizeof(S)); }

returns 16 when compiled with clang++ -std=c++17 -D_LIBCPP_ABI_VERSION=1 (or before this patch), but 8 when compiled (after this patch) with clang++ -std=c++17 -D_LIBCPP_ABI_VERSION=2.
IOW, the ABI break is confined to the new ABI; the old ABI continues working the same as before.

The iterator bases were removed in C++17 [not C++14]

Darn, you're right. I had written in my post that LWG2438 was "a very late-breaking change to C++14," but I guess it was so late that it was C++17. ;) @tcanens' HTML version of N4140 (C++14) agrees that the base classes are still there in C++14. Will change.

ldionne added inline comments.May 25 2021, 3:50 PM
libcxx/include/iterator
792

Yeah, indeed, I just realized that you were right. This is pretty terrible.

I think this can be closed now.

Quuxplusone abandoned this revision.May 31 2021, 10:15 AM