[libcxx] [test] Fix string_view tests.
test/std/strings/string.view/string.view.ops/compare.pointer_size.pass.cpp Passing -1 to size_t triggers signed/unsigned mismatch warnings because it's a value-modifying conversion. Add static_cast<size_t> to soothe the compiler. (This file refers to size_t unqualified.) test/std/strings/string.view/string.view.ops/substr.pass.cpp Add <algorithm> for std::min() and <stdexcept> for std::out_of_range. N4618 21.4.2.4 [string.view.access]/1: "Requires: pos < size()." /4: "[ Note: Unlike basic_string::operator[], basic_string_view::operator[](size()) has undefined behavior instead of returning charT(). -end note ]" Fixes D27633. git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@289283 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -16,6 +16,8 @@
|
||||
// Returns: basic_string_view(data()+pos, rlen).
|
||||
|
||||
#include <string_view>
|
||||
#include <algorithm>
|
||||
#include <stdexcept>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_macros.h"
|
||||
@@ -39,7 +41,7 @@ void test1(std::basic_string_view<CharT> sv, size_t n, size_t pos) {
|
||||
#endif
|
||||
const size_t rlen = std::min(n, sv.size() - pos);
|
||||
assert (sv1.size() == rlen);
|
||||
for (size_t i = 0; i <= rlen; ++i)
|
||||
for (size_t i = 0; i < rlen; ++i)
|
||||
assert(sv[pos+i] == sv1[i]);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user