This is an archive of the discontinued LLVM Phabricator instance.

[libcxx] Add checks for unique value of array<T, 0>.begin() and array<T, 0>.end() .
ClosedPublic

Authored by amakc11 on Dec 6 2018, 5:42 AM.

Details

Reviewers
EricWF
ldionne
Summary

The standard section array.zero requires the return value of begin() and end() methods of a zero-sized array to be unique. Eric Fiselier clarifies: "That unique value cannot be null, and must be properly aligned". This patch adds checks for the first part of this clarification: unique value returned by these methods cannot be null.

Diff Detail

Event Timeline

amakc11 created this revision.Dec 6 2018, 5:42 AM
ldionne added inline comments.Dec 6 2018, 5:59 AM
test/std/containers/sequences/array/begin.pass.cpp
49

Comparing the iterator to nullptr assumes the iterators to be pointers, which I don't think is required. They're only required to be contiguous iterators.

amakc11 updated this revision to Diff 176963.Dec 6 2018, 6:40 AM

In libc++ these array iterators declared as follows:

typedef value_type*                        iterator;
typedef const value_type*                  const_iterator;

The asserts changed to LIBCPP_ASSERTs.

ldionne accepted this revision.Dec 6 2018, 10:14 AM

Ahh, you're right. Ok, LGTM.

This revision is now accepted and ready to land.Dec 6 2018, 10:14 AM
ldionne closed this revision.Dec 6 2018, 10:27 AM

Committed as r348509.

test/std/containers/sequences/array/begin.pass.cpp
49

This doesn't compile because you're missing an include of "test_macros.h". Please make a habit of running the tests before submitting a review.

amakc11 updated this revision to Diff 177006.Dec 6 2018, 10:33 AM

Sorry. Fixed.

In libc++ these array iterators declared as follows:

typedef value_type*                        iterator;
typedef const value_type*                  const_iterator;

Yes, but that's just true for libc++. Other library maintainers use these tests, too.
(and frankly, I screwed up when I implemented <array>. Those iterators should not be pointers)

Yes, but that's just true for libc++. Other library maintainers use these tests, too.

It is also true for GNU libstdc++.