[libcxx] r228981 - Move the test for zero-length into the char_traits (from string_view). Add tests to char_traits specializations
Marshall Clow
mclow.lists at gmail.com
Thu Feb 12 15:34:52 PST 2015
Author: marshall
Date: Thu Feb 12 17:34:52 2015
New Revision: 228981
URL: http://llvm.org/viewvc/llvm-project?rev=228981&view=rev
Log:
Move the test for zero-length into the char_traits (from string_view). Add tests to char_traits specializations
Modified:
libcxx/trunk/include/experimental/string_view
libcxx/trunk/include/string
libcxx/trunk/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char/compare.pass.cpp
libcxx/trunk/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/compare.pass.cpp
libcxx/trunk/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/compare.pass.cpp
libcxx/trunk/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/compare.pass.cpp
Modified: libcxx/trunk/include/experimental/string_view
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/experimental/string_view?rev=228981&r1=228980&r2=228981&view=diff
==============================================================================
--- libcxx/trunk/include/experimental/string_view (original)
+++ libcxx/trunk/include/experimental/string_view Thu Feb 12 17:34:52 2015
@@ -375,7 +375,7 @@ _LIBCPP_BEGIN_NAMESPACE_LFTS
_LIBCPP_CONSTEXPR_AFTER_CXX11 int compare(basic_string_view __sv) const _NOEXCEPT
{
size_type __rlen = _VSTD::min( size(), __sv.size());
- int __retval = __rlen == 0 ? 0 : _Traits::compare(data(), __sv.data(), __rlen);
+ int __retval = _Traits::compare(data(), __sv.data(), __rlen);
if ( __retval == 0 ) // first __rlen chars matched
__retval = size() == __sv.size() ? 0 : ( size() < __sv.size() ? -1 : 1 );
return __retval;
Modified: libcxx/trunk/include/string
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/string?rev=228981&r1=228980&r2=228981&view=diff
==============================================================================
--- libcxx/trunk/include/string (original)
+++ libcxx/trunk/include/string Thu Feb 12 17:34:52 2015
@@ -636,7 +636,7 @@ struct _LIBCPP_TYPE_VIS_ONLY char_traits
{return (unsigned char)__c1 < (unsigned char)__c2;}
static inline int compare(const char_type* __s1, const char_type* __s2, size_t __n)
- {return memcmp(__s1, __s2, __n);}
+ {return __n == 0 ? 0 : memcmp(__s1, __s2, __n);}
static inline size_t length(const char_type* __s) {return strlen(__s);}
static inline const char_type* find(const char_type* __s, size_t __n, const char_type& __a)
{return (const char_type*)memchr(__s, to_int_type(__a), __n);}
@@ -681,7 +681,7 @@ struct _LIBCPP_TYPE_VIS_ONLY char_traits
{return __c1 < __c2;}
static inline int compare(const char_type* __s1, const char_type* __s2, size_t __n)
- {return wmemcmp(__s1, __s2, __n);}
+ {return __n == 0 ? 0 : wmemcmp(__s1, __s2, __n);}
static inline size_t length(const char_type* __s)
{return wcslen(__s);}
static inline const char_type* find(const char_type* __s, size_t __n, const char_type& __a)
Modified: libcxx/trunk/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char/compare.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char/compare.pass.cpp?rev=228981&r1=228980&r2=228981&view=diff
==============================================================================
--- libcxx/trunk/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char/compare.pass.cpp (original)
+++ libcxx/trunk/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char/compare.pass.cpp Thu Feb 12 17:34:52 2015
@@ -19,6 +19,7 @@
int main()
{
assert(std::char_traits<char>::compare("", "", 0) == 0);
+ assert(std::char_traits<char>::compare(NULL, NULL, 0) == 0);
assert(std::char_traits<char>::compare("1", "1", 1) == 0);
assert(std::char_traits<char>::compare("1", "2", 1) < 0);
Modified: libcxx/trunk/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/compare.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/compare.pass.cpp?rev=228981&r1=228980&r2=228981&view=diff
==============================================================================
--- libcxx/trunk/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/compare.pass.cpp (original)
+++ libcxx/trunk/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/compare.pass.cpp Thu Feb 12 17:34:52 2015
@@ -21,6 +21,7 @@ int main()
#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
#if __cplusplus >= 201103L
assert(std::char_traits<char16_t>::compare(u"", u"", 0) == 0);
+ assert(std::char_traits<char16_t>::compare(NULL, NULL, 0) == 0);
assert(std::char_traits<char16_t>::compare(u"1", u"1", 1) == 0);
assert(std::char_traits<char16_t>::compare(u"1", u"2", 1) < 0);
Modified: libcxx/trunk/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/compare.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/compare.pass.cpp?rev=228981&r1=228980&r2=228981&view=diff
==============================================================================
--- libcxx/trunk/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/compare.pass.cpp (original)
+++ libcxx/trunk/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/compare.pass.cpp Thu Feb 12 17:34:52 2015
@@ -21,6 +21,7 @@ int main()
#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
#if __cplusplus >= 201103L
assert(std::char_traits<char32_t>::compare(U"", U"", 0) == 0);
+ assert(std::char_traits<char32_t>::compare(NULL, NULL, 0) == 0);
assert(std::char_traits<char32_t>::compare(U"1", U"1", 1) == 0);
assert(std::char_traits<char32_t>::compare(U"1", U"2", 1) < 0);
Modified: libcxx/trunk/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/compare.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/compare.pass.cpp?rev=228981&r1=228980&r2=228981&view=diff
==============================================================================
--- libcxx/trunk/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/compare.pass.cpp (original)
+++ libcxx/trunk/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/compare.pass.cpp Thu Feb 12 17:34:52 2015
@@ -19,6 +19,7 @@
int main()
{
assert(std::char_traits<wchar_t>::compare(L"", L"", 0) == 0);
+ assert(std::char_traits<wchar_t>::compare(NULL, NULL, 0) == 0);
assert(std::char_traits<wchar_t>::compare(L"1", L"1", 1) == 0);
assert(std::char_traits<wchar_t>::compare(L"1", L"2", 1) < 0);
More information about the cfe-commits
mailing list