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<char16_t *>(1);
- }
-}
-
-ConstChar16Ptr::ConstChar16Ptr(int null) : p(nullptr) {
- U_ASSERT(null == 0);
- if (null != 0) {
- // Try to provoke a crash.
- p = reinterpret_cast<char16_t *>(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<char16_t *>(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<char16_t *>(1);
- }
-}
-
-#endif
-
U_NAMESPACE_END
#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 {
* @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
#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); }
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;
#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 {
* @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
#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); }
#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;
TESTCASE_AUTO(TestUInt16Pointers);
TESTCASE_AUTO(TestWCharPointers);
TESTCASE_AUTO(TestNullPointers);
- TESTCASE_AUTO(TestZeroPointers);
TESTCASE_AUTO_END;
}
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);
-}