Author: stl_msft Date: Fri Dec 9 16:35:53 2016 New Revision: 289283 URL: http://llvm.org/viewvc/llvm-project?rev=289283&view=rev Log: [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. Modified: libcxx/trunk/test/std/strings/string.view/string.view.ops/compare.pointer_size.pass.cpp libcxx/trunk/test/std/strings/string.view/string.view.ops/substr.pass.cpp Modified: libcxx/trunk/test/std/strings/string.view/string.view.ops/compare.pointer_size.pass.cpp URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/string.view/string.view.ops/compare.pointer_size.pass.cpp?rev=289283&r1=289282&r2=289283&view=diff ============================================================================== --- libcxx/trunk/test/std/strings/string.view/string.view.ops/compare.pointer_size.pass.cpp (original) +++ libcxx/trunk/test/std/strings/string.view/string.view.ops/compare.pointer_size.pass.cpp Fri Dec 9 16:35:53 2016 @@ -376,7 +376,7 @@ int main() test("abcdefghijklmnopqrst", 5, 5, "", 20); test("abcdefghijklmnopqrst", 0, 8, "abcde", 15); test("abcdefghijklmnopqrst", 0, 12, "abcdefghij", 10); - test("abcdefghijklmnopqrst", 0, -1, "abcdefghijklmnopqrst", 0); + test("abcdefghijklmnopqrst", 0, static_cast<size_t>(-1), "abcdefghijklmnopqrst", 0); } { @@ -395,7 +395,7 @@ int main() test(L"abcdefghijklmnopqrst", 5, 5, L"", 20); test(L"abcdefghijklmnopqrst", 0, 8, L"abcde", 15); test(L"abcdefghijklmnopqrst", 0, 12, L"abcdefghij", 10); - test(L"abcdefghijklmnopqrst", 0, -1, L"abcdefghijklmnopqrst", 0); + test(L"abcdefghijklmnopqrst", 0, static_cast<size_t>(-1), L"abcdefghijklmnopqrst", 0); } #if TEST_STD_VER >= 11 @@ -415,7 +415,7 @@ int main() test(U"abcdefghijklmnopqrst", 5, 5, U"", 20); test(U"abcdefghijklmnopqrst", 0, 8, U"abcde", 15); test(U"abcdefghijklmnopqrst", 0, 12, U"abcdefghij", 10); - test(U"abcdefghijklmnopqrst", 0, -1, U"abcdefghijklmnopqrst", 0); + test(U"abcdefghijklmnopqrst", 0, static_cast<size_t>(-1), U"abcdefghijklmnopqrst", 0); } { @@ -434,7 +434,7 @@ int main() test(u"abcdefghijklmnopqrst", 5, 5, u"", 20); test(u"abcdefghijklmnopqrst", 0, 8, u"abcde", 15); test(u"abcdefghijklmnopqrst", 0, 12, u"abcdefghij", 10); - test(u"abcdefghijklmnopqrst", 0, -1, u"abcdefghijklmnopqrst", 0); + test(u"abcdefghijklmnopqrst", 0, static_cast<size_t>(-1), u"abcdefghijklmnopqrst", 0); } #endif Modified: libcxx/trunk/test/std/strings/string.view/string.view.ops/substr.pass.cpp URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/string.view/string.view.ops/substr.pass.cpp?rev=289283&r1=289282&r2=289283&view=diff ============================================================================== --- libcxx/trunk/test/std/strings/string.view/string.view.ops/substr.pass.cpp (original) +++ libcxx/trunk/test/std/strings/string.view/string.view.ops/substr.pass.cpp Fri Dec 9 16:35:53 2016 @@ -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> #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]); } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits