This is an archive of the discontinued LLVM Phabricator instance.

[libcxx][test] the domain of == for forward iterators is iterator values from the same range
ClosedPublic

Authored by CaseyCarter on Jan 24 2022, 8:51 AM.

Details

Summary
  • Default-initialized basic_string iterators are not portably in the domain of ==.
  • Avoid comparing iterators from non-equal string_views which MSVCSTL considers not to be in the domain of equality.
  • Don't test invalid range [in, out + N).

Also silence some truncation warnings by testing with a non-narrowing conversion.

Diff Detail

Event Timeline

CaseyCarter requested review of this revision.Jan 24 2022, 8:51 AM
CaseyCarter created this revision.
Herald added 1 blocking reviewer(s): Restricted Project. · View Herald TranscriptJan 24 2022, 8:51 AM
Quuxplusone added a subscriber: Quuxplusone.

LGTM % discussion on whether we should eliminate the bogus test in libcxx/test/std/strings/basic.string/string.iterators/iterators.pass.cpp entirely.

libcxx/test/std/strings/basic.string/string.iterators/iterators.pass.cpp
56–57

Default-initialized basic_string iterators are not portably in the domain of ==.

Oh yeah, because they can conformingly be just garbage-initialized const char*s, right? Makes sense. We probably shouldn't even be testing this case, then.

libcxx/test/std/utilities/memory/specialized.algorithms/uninitialized.copy/ranges_uninitialized_copy.pass.cpp
221

Mild yikes. Did MSVC catch this with a warning, instrumented debug iterators, or otherwise?

328

This is "silence some truncation warnings," right? SGTM.

Review comment.

CaseyCarter marked an inline comment as done.Jan 24 2022, 10:00 AM
CaseyCarter added inline comments.
libcxx/test/std/strings/basic.string/string.iterators/iterators.pass.cpp
56–57

I'll strike.

libcxx/test/std/utilities/memory/specialized.algorithms/uninitialized.copy/ranges_uninitialized_copy.pass.cpp
221

Range validity checks - we check first <= last when both are pointers - caught both occurrences when the compiler decided to place out before in on the stack.

libcxx/test/std/utilities/memory/specialized.algorithms/uninitialized.copy/ranges_uninitialized_copy.pass.cpp
221

Ah, neat (but also disappointingly arbitrary :)). I wonder if there's a Clang option to randomize stack layout, or if ASAN/MSAN/UBSAN would catch unrelated pointer comparisons like that and if so could we turn it on for our debug-build CI, which also includes variations on _LIBCPP_ASSERT(first <= last).

ldionne accepted this revision.Jan 24 2022, 12:40 PM
This revision is now accepted and ready to land.Jan 24 2022, 12:40 PM