diff --git a/icu4c/source/common/char16ptr.cpp b/icu4c/source/common/char16ptr.cpp index 1da9cd8490c..5afec2af303 100644 --- a/icu4c/source/common/char16ptr.cpp +++ b/icu4c/source/common/char16ptr.cpp @@ -10,46 +10,4 @@ U_NAMESPACE_BEGIN -#ifdef U_ALIASING_BARRIER - -Char16Ptr::Char16Ptr(int null) : p(nullptr) { - U_ASSERT(null == 0); - if (null != 0) { - // Try to provoke a crash. - p = reinterpret_cast(1); - } -} - -ConstChar16Ptr::ConstChar16Ptr(int null) : p(nullptr) { - U_ASSERT(null == 0); - if (null != 0) { - // Try to provoke a crash. - p = reinterpret_cast(1); - } -} - -#else - -Char16Ptr::Char16Ptr(int null) { - U_ASSERT(null == 0); - if (null == 0) { - u.cp = nullptr; - } else { - // Try to provoke a crash. - u.cp = reinterpret_cast(1); - } -} - -ConstChar16Ptr::ConstChar16Ptr(int null) { - U_ASSERT(null == 0); - if (null == 0) { - u.cp = nullptr; - } else { - // Try to provoke a crash. - u.cp = reinterpret_cast(1); - } -} - -#endif - U_NAMESPACE_END diff --git a/icu4c/source/common/unicode/char16ptr.h b/icu4c/source/common/unicode/char16ptr.h index a949b7d4f54..672fa46ed27 100644 --- a/icu4c/source/common/unicode/char16ptr.h +++ b/icu4c/source/common/unicode/char16ptr.h @@ -30,8 +30,7 @@ U_NAMESPACE_BEGIN #endif /** - * char16_t * wrapper with implicit conversion from distinct but bit-compatible pointer types, - * and from NULL. + * char16_t * wrapper with implicit conversion from/to distinct but bit-compatible pointer types. * @draft ICU 59 */ class U_COMMON_API Char16Ptr final { @@ -60,12 +59,6 @@ public: * @draft ICU 59 */ inline Char16Ptr(std::nullptr_t p); - /** - * NULL constructor. - * Must only be used for 0 which is usually the value of NULL. - * @draft ICU 59 - */ - Char16Ptr(int null); /** * Destructor. * @draft ICU 59 @@ -97,7 +90,7 @@ public: #endif operator void *() const { return get(); } - char16_t operator[](size_t offset) const { return get()[offset]; } + char16_t operator[](std::ptrdiff_t offset) const { return get()[offset]; } UBool operator==(const Char16Ptr &other) const { return get() == other.get(); } UBool operator!=(const Char16Ptr &other) const { return !operator==(other); } @@ -112,19 +105,19 @@ public: UBool operator==(const std::nullptr_t null) const { return get() == null; } UBool operator!=(const std::nullptr_t null) const { return !operator==(null); } /** - * Comparison with NULL. - * @return TRUE if the pointer is nullptr and null==0 + * Comparison with 0. + * @return TRUE if the pointer is nullptr and zero==0 * @draft ICU 59 */ - UBool operator==(int null) const { return get() == nullptr && null == 0; } + UBool operator==(int zero) const { return get() == nullptr && zero == 0; } /** - * Comparison with NULL. - * @return TRUE if the pointer is not nullptr and null==0 + * Comparison with 0. + * @return TRUE if the pointer is not nullptr and zero==0 * @draft ICU 59 */ - UBool operator!=(int null) const { return get() != nullptr && null == 0; } + UBool operator!=(int zero) const { return get() != nullptr && zero == 0; } - Char16Ptr operator+(size_t offset) const { return Char16Ptr(get() + offset); } + Char16Ptr operator+(std::ptrdiff_t offset) const { return Char16Ptr(get() + offset); } private: Char16Ptr() = delete; @@ -194,8 +187,7 @@ Char16Ptr::operator wchar_t *() const { #endif /** - * const char16_t * wrapper with implicit conversion from distinct but bit-compatible pointer types, - * and from NULL. + * const char16_t * wrapper with implicit conversion from/to distinct but bit-compatible pointer types. * @draft ICU 59 */ class U_COMMON_API ConstChar16Ptr final { @@ -223,12 +215,6 @@ public: * @draft ICU 59 */ inline ConstChar16Ptr(const std::nullptr_t p); - /** - * NULL constructor. - * Must only be used for 0 which is usually the value of NULL. - * @draft ICU 59 - */ - ConstChar16Ptr(int null); /** * Destructor. * @draft ICU 59 @@ -259,7 +245,7 @@ public: #endif operator const void *() const { return get(); } - char16_t operator[](size_t offset) const { return get()[offset]; } + char16_t operator[](std::ptrdiff_t offset) const { return get()[offset]; } UBool operator==(const ConstChar16Ptr &other) const { return get() == other.get(); } UBool operator!=(const ConstChar16Ptr &other) const { return !operator==(other); } @@ -273,10 +259,10 @@ public: #endif UBool operator==(const std::nullptr_t null) const { return get() == null; } UBool operator!=(const std::nullptr_t null) const { return !operator==(null); } - UBool operator==(int null) const { return get() == nullptr && null == 0; } - UBool operator!=(int null) const { return get() != nullptr && null == 0; } + UBool operator==(int zero) const { return get() == nullptr && zero == 0; } + UBool operator!=(int zero) const { return get() != nullptr && zero == 0; } - ConstChar16Ptr operator+(size_t offset) { return ConstChar16Ptr(get() + offset); } + ConstChar16Ptr operator+(std::ptrdiff_t offset) { return ConstChar16Ptr(get() + offset); } private: ConstChar16Ptr() = delete; diff --git a/icu4c/source/common/unicode/unistr.h b/icu4c/source/common/unicode/unistr.h index 331b01281ad..3dd2fa6c2a5 100644 --- a/icu4c/source/common/unicode/unistr.h +++ b/icu4c/source/common/unicode/unistr.h @@ -3943,7 +3943,7 @@ UnicodeString::isBufferWritable() const inline ConstChar16Ptr UnicodeString::getBuffer() const { if(fUnion.fFields.fLengthAndFlags&(kIsBogus|kOpenGetBuffer)) { - return 0; + return nullptr; } else if(fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) { return fUnion.fStackFields.fBuffer; } else { diff --git a/icu4c/source/common/unistr.cpp b/icu4c/source/common/unistr.cpp index 10c781746e1..3657d15e0f3 100644 --- a/icu4c/source/common/unistr.cpp +++ b/icu4c/source/common/unistr.cpp @@ -1221,7 +1221,7 @@ UnicodeString::unBogus() { ConstChar16Ptr UnicodeString::getTerminatedBuffer() { if(!isWritable()) { - return 0; + return nullptr; } UChar *array = getArrayStart(); int32_t len = length(); @@ -1723,7 +1723,7 @@ UnicodeString::getBuffer(int32_t minCapacity) { setZeroLength(); return getArrayStart(); } else { - return 0; + return nullptr; } } diff --git a/icu4c/source/test/intltest/ustrtest.cpp b/icu4c/source/test/intltest/ustrtest.cpp index 429ae325b0c..ca031b1f423 100644 --- a/icu4c/source/test/intltest/ustrtest.cpp +++ b/icu4c/source/test/intltest/ustrtest.cpp @@ -64,7 +64,6 @@ void UnicodeStringTest::runIndexedTest( int32_t index, UBool exec, const char* & TESTCASE_AUTO(TestUInt16Pointers); TESTCASE_AUTO(TestWCharPointers); TESTCASE_AUTO(TestNullPointers); - TESTCASE_AUTO(TestZeroPointers); TESTCASE_AUTO_END; } @@ -2258,18 +2257,3 @@ UnicodeStringTest::TestNullPointers() { UnicodeString(u"def").extract(nullptr, 0, errorCode); assertEquals("buffer overflow extracting to nullptr", U_BUFFER_OVERFLOW_ERROR, errorCode); } - -void -UnicodeStringTest::TestZeroPointers() { - // There are constructor overloads with one and three integer parameters - // which match passing 0, so we cannot test using 0 for UnicodeString(pointer) - // or UnicodeString(read-only or writable alias). - // There are multiple two-parameter constructors that make using 0 - // for the first parameter ambiguous already, - // so we cannot test using 0 for UnicodeString(pointer, length). - - // extract() also has enough overloads to be ambiguous with 0. - // Test the pointer wrapper directly. - assertTrue("0 --> nullptr", Char16Ptr(0).get() == nullptr); - assertTrue("0 --> const nullptr", ConstChar16Ptr(0).get() == nullptr); -} diff --git a/icu4c/source/test/intltest/ustrtest.h b/icu4c/source/test/intltest/ustrtest.h index a2e2fbd4b71..4ba348c431f 100644 --- a/icu4c/source/test/intltest/ustrtest.h +++ b/icu4c/source/test/intltest/ustrtest.h @@ -96,7 +96,6 @@ public: void TestUInt16Pointers(); void TestWCharPointers(); void TestNullPointers(); - void TestZeroPointers(); }; #endif