diff --git a/.github/workflows/icu_ci.yml b/.github/workflows/icu_ci.yml index 1f16614d39e..718924b68bc 100644 --- a/.github/workflows/icu_ci.yml +++ b/.github/workflows/icu_ci.yml @@ -320,6 +320,25 @@ jobs: env: CPPFLAGS: -fsanitize=address LDFLAGS: -fsanitize=address + # Control Flow Integrity. + clang-cfi: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: ICU4C with clang using CFI + run: | + cd icu4c/source; + ./runConfigureICU Linux --disable-renaming; + make -j2; + make -j2 check + env: + CC: clang + CXX: clang++ + # add -fsanitize=cfi-vcall -fsanitize=cfi-icall later + CXXFLAGS: -flto -fvisibility=hidden -fsanitize=cfi-derived-cast -fno-sanitize-trap=cfi -fno-inline-functions -fno-inline -fno-omit-frame-pointer -O1 + # add -fsanitize=cfi-vcall -fsanitize=cfi-icall later + LDFLAGS: -flto -fvisibility=hidden -fuse-ld=gold -fsanitize=cfi-derived-cast -fsanitize=cfi-unrelated-cast -fno-sanitize-trap=cfi -fsanitize-cfi-icall-generalize-pointers # Clang Linux with thread sanitizer. clang-tsan: diff --git a/icu4c/source/common/brkiter.cpp b/icu4c/source/common/brkiter.cpp index 478e7676fb0..9ef2d063ff4 100644 --- a/icu4c/source/common/brkiter.cpp +++ b/icu4c/source/common/brkiter.cpp @@ -260,7 +260,7 @@ public: } virtual UObject* handleDefault(const ICUServiceKey& key, UnicodeString* /*actualID*/, UErrorCode& status) const override { - LocaleKey& lkey = (LocaleKey&)key; + LocaleKey& lkey = static_cast(const_cast(key)); int32_t kind = lkey.kind(); Locale loc; lkey.currentLocale(loc); diff --git a/icu4c/source/common/bytestriebuilder.cpp b/icu4c/source/common/bytestriebuilder.cpp index 0582f1aa11a..876e0dfa160 100644 --- a/icu4c/source/common/bytestriebuilder.cpp +++ b/icu4c/source/common/bytestriebuilder.cpp @@ -351,13 +351,13 @@ BytesTrieBuilder::BTLinearMatchNode::operator==(const Node &other) const { if(!LinearMatchNode::operator==(other)) { return false; } - const BTLinearMatchNode &o=(const BTLinearMatchNode &)other; + const BTLinearMatchNode &o=static_cast(other); return 0==uprv_memcmp(s, o.s, length); } void BytesTrieBuilder::BTLinearMatchNode::write(StringTrieBuilder &builder) { - BytesTrieBuilder &b=(BytesTrieBuilder &)builder; + BytesTrieBuilder &b=static_cast(builder); next->write(builder); b.write(s, length); offset=b.write(b.getMinLinearMatch()+length-1); diff --git a/icu4c/source/common/rbbi.cpp b/icu4c/source/common/rbbi.cpp index 38bec16e9b1..8a31ca6f2ca 100644 --- a/icu4c/source/common/rbbi.cpp +++ b/icu4c/source/common/rbbi.cpp @@ -362,7 +362,7 @@ RuleBasedBreakIterator::operator==(const BreakIterator& that) const { // and does not implement an equality function that would otherwise be // checked at this point. - const RuleBasedBreakIterator& that2 = (const RuleBasedBreakIterator&) that; + const RuleBasedBreakIterator& that2 = static_cast(that); if (!utext_equals(&fText, &that2.fText)) { // The two break iterators are operating on different text, diff --git a/icu4c/source/common/schriter.cpp b/icu4c/source/common/schriter.cpp index 83b3db4ab0a..d4bac8fd4f2 100644 --- a/icu4c/source/common/schriter.cpp +++ b/icu4c/source/common/schriter.cpp @@ -93,7 +93,7 @@ StringCharacterIterator::operator==(const ForwardCharacterIterator& that) const return false; } - StringCharacterIterator& realThat = (StringCharacterIterator&)that; + const StringCharacterIterator& realThat = static_cast(that); return text == realThat.text && pos == realThat.pos diff --git a/icu4c/source/common/serv.cpp b/icu4c/source/common/serv.cpp index b4df576187f..5248f7c192b 100644 --- a/icu4c/source/common/serv.cpp +++ b/icu4c/source/common/serv.cpp @@ -941,7 +941,7 @@ ICUService::acceptsListener(const EventListener& l) const void ICUService::notifyListener(EventListener& l) const { - ((ServiceListener&)l).serviceChanged(*this); + (static_cast(l)).serviceChanged(*this); } UnicodeString& diff --git a/icu4c/source/common/servlkf.cpp b/icu4c/source/common/servlkf.cpp index 935f6b71b3e..f5bb0418c4e 100644 --- a/icu4c/source/common/servlkf.cpp +++ b/icu4c/source/common/servlkf.cpp @@ -47,7 +47,7 @@ LocaleKeyFactory::~LocaleKeyFactory() { UObject* LocaleKeyFactory::create(const ICUServiceKey& key, const ICUService* service, UErrorCode& status) const { if (handlesKey(key, status)) { - const LocaleKey& lkey = (const LocaleKey&)key; + const LocaleKey& lkey = static_cast(key); int32_t kind = lkey.kind(); Locale loc; lkey.currentLocale(loc); diff --git a/icu4c/source/common/servslkf.cpp b/icu4c/source/common/servslkf.cpp index 7aa2ee71b89..b3ab1cc9ce9 100644 --- a/icu4c/source/common/servslkf.cpp +++ b/icu4c/source/common/servslkf.cpp @@ -64,7 +64,7 @@ UObject* SimpleLocaleKeyFactory::create(const ICUServiceKey& key, const ICUService* service, UErrorCode& status) const { if (U_SUCCESS(status)) { - const LocaleKey& lkey = (const LocaleKey&)key; + const LocaleKey& lkey = static_cast(key); if (_kind == LocaleKey::KIND_ANY || _kind == lkey.kind()) { UnicodeString keyID; lkey.currentID(keyID); diff --git a/icu4c/source/common/stringtriebuilder.cpp b/icu4c/source/common/stringtriebuilder.cpp index c577ff017b5..2a40dc88fd8 100644 --- a/icu4c/source/common/stringtriebuilder.cpp +++ b/icu4c/source/common/stringtriebuilder.cpp @@ -404,7 +404,7 @@ StringTrieBuilder::FinalValueNode::operator==(const Node &other) const { if(!Node::operator==(other)) { return false; } - const FinalValueNode &o=(const FinalValueNode &)other; + const FinalValueNode &o=static_cast(other); return value==o.value; } @@ -421,7 +421,7 @@ StringTrieBuilder::ValueNode::operator==(const Node &other) const { if(!Node::operator==(other)) { return false; } - const ValueNode &o=(const ValueNode &)other; + const ValueNode &o=static_cast(other); return hasValue==o.hasValue && (!hasValue || value==o.value); } @@ -433,7 +433,7 @@ StringTrieBuilder::IntermediateValueNode::operator==(const Node &other) const { if(!ValueNode::operator==(other)) { return false; } - const IntermediateValueNode &o=(const IntermediateValueNode &)other; + const IntermediateValueNode &o=static_cast(other); return next==o.next; } @@ -459,7 +459,7 @@ StringTrieBuilder::LinearMatchNode::operator==(const Node &other) const { if(!ValueNode::operator==(other)) { return false; } - const LinearMatchNode &o=(const LinearMatchNode &)other; + const LinearMatchNode &o=static_cast(other); return length==o.length && next==o.next; } @@ -479,7 +479,7 @@ StringTrieBuilder::ListBranchNode::operator==(const Node &other) const { if(!Node::operator==(other)) { return false; } - const ListBranchNode &o=(const ListBranchNode &)other; + const ListBranchNode &o=static_cast(other); for(int32_t i=0; i(other); return unit==o.unit && lessThan==o.lessThan && greaterOrEqual==o.greaterOrEqual; } @@ -592,7 +592,7 @@ StringTrieBuilder::BranchHeadNode::operator==(const Node &other) const { if(!ValueNode::operator==(other)) { return false; } - const BranchHeadNode &o=(const BranchHeadNode &)other; + const BranchHeadNode &o=static_cast(other); return length==o.length && next==o.next; } diff --git a/icu4c/source/common/ucharstriebuilder.cpp b/icu4c/source/common/ucharstriebuilder.cpp index 4bb5450c12f..95b32711a8e 100644 --- a/icu4c/source/common/ucharstriebuilder.cpp +++ b/icu4c/source/common/ucharstriebuilder.cpp @@ -298,7 +298,7 @@ UCharsTrieBuilder::UCTLinearMatchNode::operator==(const Node &other) const { if(!LinearMatchNode::operator==(other)) { return false; } - const UCTLinearMatchNode &o=(const UCTLinearMatchNode &)other; + const UCTLinearMatchNode &o=static_cast(other); return 0==u_memcmp(s, o.s, length); } diff --git a/icu4c/source/common/uchriter.cpp b/icu4c/source/common/uchriter.cpp index 89c1b418db6..a7d30977e09 100644 --- a/icu4c/source/common/uchriter.cpp +++ b/icu4c/source/common/uchriter.cpp @@ -75,7 +75,7 @@ UCharCharacterIterator::operator==(const ForwardCharacterIterator& that) const { return false; } - UCharCharacterIterator& realThat = (UCharCharacterIterator&)that; + const UCharCharacterIterator& realThat = static_cast(that); return text == realThat.text && textLength == realThat.textLength diff --git a/icu4c/source/common/unistr.cpp b/icu4c/source/common/unistr.cpp index f05a6c68081..2c6659b115d 100644 --- a/icu4c/source/common/unistr.cpp +++ b/icu4c/source/common/unistr.cpp @@ -527,7 +527,7 @@ UnicodeString::copyFrom(const UnicodeString &src, UBool fastCopy) { case kLongString: // src uses a refCounted string buffer, use that buffer with refCount // src is const, use a cast - we don't actually change it - ((UnicodeString &)src).addRef(); + const_cast(src).addRef(); // copy all fields, share the reference-counted buffer fUnion.fFields.fArray = src.fUnion.fFields.fArray; fUnion.fFields.fCapacity = src.fUnion.fFields.fCapacity; diff --git a/icu4c/source/i18n/calendar.cpp b/icu4c/source/i18n/calendar.cpp index bb89dffce26..b8209f63ffa 100644 --- a/icu4c/source/i18n/calendar.cpp +++ b/icu4c/source/i18n/calendar.cpp @@ -449,12 +449,13 @@ protected: fprintf(stderr, "::create - not a LocaleKey!\n"); } #endif - const LocaleKey& lkey = (LocaleKey&)key; + const LocaleKey* lkey = dynamic_cast(&key); + U_ASSERT(lkey != nullptr); Locale curLoc; // current locale Locale canLoc; // Canonical locale - lkey.currentLocale(curLoc); - lkey.canonicalLocale(canLoc); + lkey->currentLocale(curLoc); + lkey->canonicalLocale(canLoc); char keyword[ULOC_FULLNAME_CAPACITY]; UnicodeString str; @@ -494,9 +495,10 @@ protected: return nullptr; } - LocaleKey &lkey = (LocaleKey&)key; + const LocaleKey *lkey = dynamic_cast(&key); + U_ASSERT(lkey != nullptr); Locale loc; - lkey.currentLocale(loc); + lkey->currentLocale(loc); UnicodeString *ret = new UnicodeString(); if (ret == nullptr) { @@ -541,7 +543,7 @@ public: if (U_FAILURE(status)) { return nullptr; } - LocaleKey& lkey = (LocaleKey&)key; + LocaleKey& lkey = static_cast(const_cast(key)); //int32_t kind = lkey.kind(); Locale loc; diff --git a/icu4c/source/i18n/choicfmt.cpp b/icu4c/source/i18n/choicfmt.cpp index d160f2c05f6..96e73fabcfa 100644 --- a/icu4c/source/i18n/choicfmt.cpp +++ b/icu4c/source/i18n/choicfmt.cpp @@ -137,7 +137,7 @@ ChoiceFormat::operator==(const Format& that) const { if (this == &that) return true; if (!NumberFormat::operator==(that)) return false; - ChoiceFormat& thatAlias = (ChoiceFormat&)that; + const ChoiceFormat& thatAlias = static_cast(that); return msgPattern == thatAlias.msgPattern; } diff --git a/icu4c/source/i18n/coll.cpp b/icu4c/source/i18n/coll.cpp index 6d6587275ed..5634ee8bb05 100644 --- a/icu4c/source/i18n/coll.cpp +++ b/icu4c/source/i18n/coll.cpp @@ -137,7 +137,7 @@ ICUCollatorFactory::~ICUCollatorFactory() {} UObject* ICUCollatorFactory::create(const ICUServiceKey& key, const ICUService* /* service */, UErrorCode& status) const { if (handlesKey(key, status)) { - const LocaleKey& lkey = (const LocaleKey&)key; + const LocaleKey& lkey = static_cast(key); Locale loc; // make sure the requested locale is correct // default LocaleFactory uses currentLocale since that's the one vetted by handlesKey @@ -167,7 +167,8 @@ public: } virtual UObject* handleDefault(const ICUServiceKey& key, UnicodeString* actualID, UErrorCode& status) const override { - LocaleKey& lkey = (LocaleKey&)key; + const LocaleKey* lkey = dynamic_cast(&key); + U_ASSERT(lkey != nullptr); if (actualID) { // Ugly Hack Alert! We return an empty actualID to signal // to callers that this is a default object, not a "real" @@ -175,7 +176,7 @@ public: actualID->truncate(0); } Locale loc(""); - lkey.canonicalLocale(loc); + lkey->canonicalLocale(loc); return Collator::makeInstance(loc, status); } @@ -746,9 +747,10 @@ UObject* CFactory::create(const ICUServiceKey& key, const ICUService* /* service */, UErrorCode& status) const { if (handlesKey(key, status)) { - const LocaleKey& lkey = (const LocaleKey&)key; + const LocaleKey* lkey = dynamic_cast(&key); + U_ASSERT(lkey != nullptr); Locale validLoc; - lkey.currentLocale(validLoc); + lkey->currentLocale(validLoc); return _delegate->createCollator(validLoc); } return nullptr; diff --git a/icu4c/source/i18n/curramt.cpp b/icu4c/source/i18n/curramt.cpp index 6fd2ea2fda5..43c3e9c151a 100644 --- a/icu4c/source/i18n/curramt.cpp +++ b/icu4c/source/i18n/curramt.cpp @@ -44,7 +44,11 @@ CurrencyAmount* CurrencyAmount::clone() const { CurrencyAmount::~CurrencyAmount() { } - + +const CurrencyUnit& CurrencyAmount::getCurrency() const { + return static_cast(getUnit()); +} + UOBJECT_DEFINE_RTTI_IMPLEMENTATION(CurrencyAmount) U_NAMESPACE_END diff --git a/icu4c/source/i18n/msgfmt.cpp b/icu4c/source/i18n/msgfmt.cpp index c9a3f82e059..3e8f17c15ce 100644 --- a/icu4c/source/i18n/msgfmt.cpp +++ b/icu4c/source/i18n/msgfmt.cpp @@ -394,11 +394,11 @@ MessageFormat::operator==(const Format& rhs) const { if (this == &rhs) return true; - MessageFormat& that = (MessageFormat&)rhs; - // Check class ID before checking MessageFormat members - if (!Format::operator==(rhs) || - msgPattern != that.msgPattern || + if (!Format::operator==(rhs)) return false; + + const MessageFormat& that = static_cast(rhs); + if (msgPattern != that.msgPattern || fLocale != that.fLocale) { return false; } diff --git a/icu4c/source/i18n/numfmt.cpp b/icu4c/source/i18n/numfmt.cpp index fa8eb1f483c..29bb775fd1e 100644 --- a/icu4c/source/i18n/numfmt.cpp +++ b/icu4c/source/i18n/numfmt.cpp @@ -887,14 +887,15 @@ public: virtual UObject* create(const ICUServiceKey& key, const ICUService* service, UErrorCode& status) const override { if (handlesKey(key, status)) { - const LocaleKey& lkey = (const LocaleKey&)key; + const LocaleKey* lkey = dynamic_cast(&key); + U_ASSERT(lkey != nullptr); Locale loc; - lkey.canonicalLocale(loc); - int32_t kind = lkey.kind(); + lkey->canonicalLocale(loc); + int32_t kind = lkey->kind(); UObject* result = _delegate->createFormat(loc, (UNumberFormatStyle)kind); if (result == nullptr) { - result = service->getKey((ICUServiceKey&)key /* cast away const */, nullptr, this, status); + result = service->getKey(const_cast(key) /* cast away const */, nullptr, this, status); } return result; } @@ -948,10 +949,11 @@ public: } virtual UObject* handleDefault(const ICUServiceKey& key, UnicodeString* /* actualID */, UErrorCode& status) const override { - LocaleKey& lkey = (LocaleKey&)key; - int32_t kind = lkey.kind(); + const LocaleKey* lkey = dynamic_cast(&key); + U_ASSERT(lkey != nullptr); + int32_t kind = lkey->kind(); Locale loc; - lkey.currentLocale(loc); + lkey->currentLocale(loc); return NumberFormat::makeInstance(loc, (UNumberFormatStyle)kind, status); } diff --git a/icu4c/source/i18n/rbnf.cpp b/icu4c/source/i18n/rbnf.cpp index 0b0cefaea25..c929c3e2157 100644 --- a/icu4c/source/i18n/rbnf.cpp +++ b/icu4c/source/i18n/rbnf.cpp @@ -944,7 +944,7 @@ RuleBasedNumberFormat::operator==(const Format& other) const } if (typeid(*this) == typeid(other)) { - const RuleBasedNumberFormat& rhs = (const RuleBasedNumberFormat&)other; + const RuleBasedNumberFormat& rhs = static_cast(other); // test for capitalization info equality is adequately handled // by the NumberFormat test for fCapitalizationContext equality; // the info here is just derived from that. diff --git a/icu4c/source/i18n/rbtz.cpp b/icu4c/source/i18n/rbtz.cpp index fe4a0425ec7..f634d08ca6a 100644 --- a/icu4c/source/i18n/rbtz.cpp +++ b/icu4c/source/i18n/rbtz.cpp @@ -526,7 +526,7 @@ RuleBasedTimeZone::hasSameRules(const TimeZone& other) const { if (typeid(*this) != typeid(other)) { return false; } - const RuleBasedTimeZone& that = (const RuleBasedTimeZone&)other; + const RuleBasedTimeZone& that = static_cast(other); if (*fInitialRule != *(that.fInitialRule)) { return false; } @@ -549,8 +549,8 @@ RuleBasedTimeZone::getNextTransition(UDate base, UBool inclusive, TimeZoneTransi UBool found = findNext(base, inclusive, transitionTime, fromRule, toRule); if (found) { result.setTime(transitionTime); - result.setFrom((const TimeZoneRule&)*fromRule); - result.setTo((const TimeZoneRule&)*toRule); + result.setFrom(*fromRule); + result.setTo(*toRule); return true; } return false; @@ -568,8 +568,8 @@ RuleBasedTimeZone::getPreviousTransition(UDate base, UBool inclusive, TimeZoneTr UBool found = findPrev(base, inclusive, transitionTime, fromRule, toRule); if (found) { result.setTime(transitionTime); - result.setFrom((const TimeZoneRule&)*fromRule); - result.setTo((const TimeZoneRule&)*toRule); + result.setFrom(*fromRule); + result.setTo(*toRule); return true; } return false; diff --git a/icu4c/source/i18n/selfmt.cpp b/icu4c/source/i18n/selfmt.cpp index 157173c2c91..abe39bcb635 100644 --- a/icu4c/source/i18n/selfmt.cpp +++ b/icu4c/source/i18n/selfmt.cpp @@ -172,7 +172,7 @@ SelectFormat::operator==(const Format& other) const { if (!Format::operator==(other)) { return false; } - const SelectFormat& o = (const SelectFormat&)other; + const SelectFormat& o = static_cast(other); return msgPattern == o.msgPattern; } diff --git a/icu4c/source/i18n/simpletz.cpp b/icu4c/source/i18n/simpletz.cpp index ec63a6ea684..4bf9495e46b 100644 --- a/icu4c/source/i18n/simpletz.cpp +++ b/icu4c/source/i18n/simpletz.cpp @@ -991,14 +991,14 @@ SimpleTimeZone::getNextTransition(UDate base, UBool inclusive, TimeZoneTransitio UBool dstAvail = dstRule->getNextStart(base, stdRule->getRawOffset(), stdRule->getDSTSavings(), inclusive, dstDate); if (stdAvail && (!dstAvail || stdDate < dstDate)) { result.setTime(stdDate); - result.setFrom((const TimeZoneRule&)*dstRule); - result.setTo((const TimeZoneRule&)*stdRule); + result.setFrom(*dstRule); + result.setTo(*stdRule); return true; } if (dstAvail && (!stdAvail || dstDate < stdDate)) { result.setTime(dstDate); - result.setFrom((const TimeZoneRule&)*stdRule); - result.setTo((const TimeZoneRule&)*dstRule); + result.setFrom(*stdRule); + result.setTo(*dstRule); return true; } return false; @@ -1025,14 +1025,14 @@ SimpleTimeZone::getPreviousTransition(UDate base, UBool inclusive, TimeZoneTrans UBool dstAvail = dstRule->getPreviousStart(base, stdRule->getRawOffset(), stdRule->getDSTSavings(), inclusive, dstDate); if (stdAvail && (!dstAvail || stdDate > dstDate)) { result.setTime(stdDate); - result.setFrom((const TimeZoneRule&)*dstRule); - result.setTo((const TimeZoneRule&)*stdRule); + result.setFrom(*dstRule); + result.setTo(*stdRule); return true; } if (dstAvail && (!stdAvail || dstDate > stdDate)) { result.setTime(dstDate); - result.setFrom((const TimeZoneRule&)*stdRule); - result.setTo((const TimeZoneRule&)*dstRule); + result.setFrom(*stdRule); + result.setTo(*dstRule); return true; } return false; diff --git a/icu4c/source/i18n/stsearch.cpp b/icu4c/source/i18n/stsearch.cpp index da59150d9c9..ee898d5b474 100644 --- a/icu4c/source/i18n/stsearch.cpp +++ b/icu4c/source/i18n/stsearch.cpp @@ -211,9 +211,10 @@ bool StringSearch::operator==(const SearchIterator &that) const return true; } if (SearchIterator::operator ==(that)) { - StringSearch &thatsrch = (StringSearch &)that; - return (this->m_pattern_ == thatsrch.m_pattern_ && - this->m_strsrch_->collator == thatsrch.m_strsrch_->collator); + const StringSearch *thatsrch = dynamic_cast(&that); + if (thatsrch == nullptr) return false; + return (this->m_pattern_ == thatsrch->m_pattern_ && + this->m_strsrch_->collator == thatsrch->m_strsrch_->collator); } return false; } diff --git a/icu4c/source/i18n/tmutamt.cpp b/icu4c/source/i18n/tmutamt.cpp index 2753c29374a..94fd8cfa97f 100644 --- a/icu4c/source/i18n/tmutamt.cpp +++ b/icu4c/source/i18n/tmutamt.cpp @@ -63,7 +63,7 @@ TimeUnitAmount::~TimeUnitAmount() { const TimeUnit& TimeUnitAmount::getTimeUnit() const { - return (const TimeUnit&) getUnit(); + return static_cast(getUnit()); } diff --git a/icu4c/source/i18n/unicode/curramt.h b/icu4c/source/i18n/unicode/curramt.h index bbf99b53eed..e0f6aa13dd2 100644 --- a/icu4c/source/i18n/unicode/curramt.h +++ b/icu4c/source/i18n/unicode/curramt.h @@ -111,7 +111,7 @@ class U_I18N_API CurrencyAmount: public Measure { * Return the currency unit object of this object. * @stable ICU 3.0 */ - inline const CurrencyUnit& getCurrency() const; + const CurrencyUnit& getCurrency() const; /** * Return the ISO currency code of this object. @@ -120,10 +120,6 @@ class U_I18N_API CurrencyAmount: public Measure { inline const char16_t* getISOCurrency() const; }; -inline const CurrencyUnit& CurrencyAmount::getCurrency() const { - return (const CurrencyUnit&) getUnit(); -} - inline const char16_t* CurrencyAmount::getISOCurrency() const { return getCurrency().getISOCurrency(); } diff --git a/icu4c/source/test/intltest/alphaindextst.cpp b/icu4c/source/test/intltest/alphaindextst.cpp index 26a63d115ee..f993f59daea 100644 --- a/icu4c/source/test/intltest/alphaindextst.cpp +++ b/icu4c/source/test/intltest/alphaindextst.cpp @@ -557,7 +557,7 @@ void AlphabeticIndexTest::TestIndexCharactersList() { void AlphabeticIndexTest::TestHaniFirst() { UErrorCode status = U_ZERO_ERROR; LocalPointer coll( - static_cast(Collator::createInstance(Locale::getRoot(), status))); + dynamic_cast(Collator::createInstance(Locale::getRoot(), status))); if (U_FAILURE(status)) { dataerrln("Failed Collator::createInstance call - %s", u_errorName(status)); @@ -587,7 +587,7 @@ void AlphabeticIndexTest::TestHaniFirst() { void AlphabeticIndexTest::TestPinyinFirst() { UErrorCode status = U_ZERO_ERROR; LocalPointer coll( - static_cast(Collator::createInstance(Locale::getChinese(), status))); + dynamic_cast(Collator::createInstance(Locale::getChinese(), status))); if (U_FAILURE(status)) { dataerrln("Failed Collator::createInstance call - %s", u_errorName(status)); return; @@ -659,7 +659,7 @@ void AlphabeticIndexTest::TestSchSt() { void AlphabeticIndexTest::TestNoLabels() { UErrorCode status = U_ZERO_ERROR; LocalPointer coll( - static_cast(Collator::createInstance(Locale::getRoot(), status))); + dynamic_cast(Collator::createInstance(Locale::getRoot(), status))); TEST_CHECK_STATUS; AlphabeticIndex index(coll.orphan(), status); TEST_CHECK_STATUS; diff --git a/icu4c/source/test/intltest/apicoll.cpp b/icu4c/source/test/intltest/apicoll.cpp index 41881b4f3aa..020c413b352 100644 --- a/icu4c/source/test/intltest/apicoll.cpp +++ b/icu4c/source/test/intltest/apicoll.cpp @@ -156,8 +156,8 @@ CollationAPITest::TestProperty(/* char* par */) doAssert((name == UnicodeString("English (United States)")), "getDisplayName failed if this is an English machine"); #endif delete col; col = 0; - RuleBasedCollator *rcol = (RuleBasedCollator *)Collator::createInstance("da_DK", - success); + RuleBasedCollator *rcol = dynamic_cast(Collator::createInstance("da_DK", + success)); if (U_FAILURE(success)) { errcheckln(success, "Collator::createInstance(\"da_DK\") failed - %s", u_errorName(success)); return; @@ -201,7 +201,7 @@ CollationAPITest::TestProperty(/* char* par */) return; } - doAssert(((RuleBasedCollator *)junk)->getRules().isEmpty(), + doAssert((dynamic_cast(junk))->getRules().isEmpty(), "The root collation should be returned for an unsupported language."); Collator *frCol = Collator::createInstance(Locale::getCanadaFrench(), success); if (U_FAILURE(success)) @@ -278,7 +278,7 @@ CollationAPITest::TestRuleBasedColl() status = U_ZERO_ERROR; Locale locale("aa", "AA"); - col3 = (RuleBasedCollator *)Collator::createInstance(locale, status); + col3 = dynamic_cast(Collator::createInstance(locale, status)); if (U_FAILURE(status)) { errln("Fallback Collator creation failed.: %s\n"); return; @@ -289,7 +289,7 @@ CollationAPITest::TestRuleBasedColl() delete col3; status = U_ZERO_ERROR; - col3 = (RuleBasedCollator *)Collator::createInstance(status); + col3 = dynamic_cast(Collator::createInstance(status)); if (U_FAILURE(status)) { errln("Default Collator creation failed.: %s\n"); return; @@ -338,7 +338,7 @@ CollationAPITest::TestRules() UErrorCode status = U_ZERO_ERROR; UnicodeString rules; - coll = (RuleBasedCollator *)Collator::createInstance(Locale::getEnglish(), status); + coll = dynamic_cast(Collator::createInstance(Locale::getEnglish(), status)); if (U_FAILURE(status)) { errcheckln(status, "English Collator creation failed. - %s", u_errorName(status)); return; @@ -646,14 +646,14 @@ CollationAPITest::TestElemIter(/* char* par */) UnicodeString testString1("XFILE What subset of all possible test cases has the highest probability of detecting the most errors?"); UnicodeString testString2("Xf_ile What subset of all possible test cases has the lowest probability of detecting the least errors?"); logln("Constructors and comparison testing...."); - CollationElementIterator *iterator1 = ((RuleBasedCollator*)col)->createCollationElementIterator(testString1); + CollationElementIterator *iterator1 = (dynamic_cast(col))->createCollationElementIterator(testString1); CharacterIterator *chariter=new StringCharacterIterator(testString1); - CollationElementIterator *coliter=((RuleBasedCollator*)col)->createCollationElementIterator(*chariter); + CollationElementIterator *coliter = (dynamic_cast(col))->createCollationElementIterator(*chariter); // copy ctor - CollationElementIterator *iterator2 = ((RuleBasedCollator*)col)->createCollationElementIterator(testString1); - CollationElementIterator *iterator3 = ((RuleBasedCollator*)col)->createCollationElementIterator(testString2); + CollationElementIterator *iterator2 = (dynamic_cast(col))->createCollationElementIterator(testString1); + CollationElementIterator *iterator3 = (dynamic_cast(col))->createCollationElementIterator(testString2); int32_t offset = iterator1->getOffset(); if (offset != 0) { @@ -861,13 +861,13 @@ CollationAPITest::TestOperators(/* char* par */) doAssert((*col3 == *col5), "Cloned collation objects not equal"); doAssert((*col4 != *col5), "Two cloned collations compared equal"); - const UnicodeString& defRules = ((RuleBasedCollator*)col3)->getRules(); + const UnicodeString& defRules = (dynamic_cast(col3))->getRules(); RuleBasedCollator* col6 = new RuleBasedCollator(defRules, success); if (U_FAILURE(success)) { errln("Creating default collation with rules failed."); return; } - doAssert((((RuleBasedCollator*)col3)->getRules() == col6->getRules()), "Default collator getRules failed"); + doAssert(((dynamic_cast(col3))->getRules() == col6->getRules()), "Default collator getRules failed"); success = U_ZERO_ERROR; RuleBasedCollator *col7 = new RuleBasedCollator(ruleset2, Collator::TERTIARY, success); @@ -922,13 +922,13 @@ CollationAPITest::TestDuplicate(/* char* par */) return; } doAssert((*col1 != *col3), "Cloned object is equal to some dummy"); - *col3 = *((RuleBasedCollator*)col1); + *col3 = *(dynamic_cast(col1)); doAssert((*col1 == *col3), "Copied object is not equal to the original"); UCollationResult res; UnicodeString first((char16_t)0x0061); UnicodeString second((char16_t)0x0062); - UnicodeString copiedEnglishRules(((RuleBasedCollator*)col1)->getRules()); + UnicodeString copiedEnglishRules((dynamic_cast(col1))->getRules()); delete col1; @@ -937,9 +937,9 @@ CollationAPITest::TestDuplicate(/* char* par */) if(res != UCOL_LESS) { errln("a should be less then b after tailoring"); } - if (((RuleBasedCollator*)col2)->getRules() != copiedEnglishRules) { + if ((dynamic_cast(col2))->getRules() != copiedEnglishRules) { errln(UnicodeString("English rule difference. ") - + copiedEnglishRules + UnicodeString("\ngetRules=") + ((RuleBasedCollator*)col2)->getRules()); + + copiedEnglishRules + UnicodeString("\ngetRules=") + (dynamic_cast(col2))->getRules()); } res = col3->compare(first, second, status); if(res != UCOL_LESS) { @@ -1963,7 +1963,7 @@ void CollationAPITest::TestUClassID() } UErrorCode status = U_ZERO_ERROR; RuleBasedCollator *coll - = (RuleBasedCollator *)Collator::createInstance(status); + = dynamic_cast(Collator::createInstance(status)); if(U_FAILURE(status)) { delete coll; errcheckln(status, "Collator creation failed with %s", u_errorName(status)); @@ -2322,7 +2322,7 @@ void CollationAPITest::TestNullptrCharTailoring() void CollationAPITest::TestClone() { logln("\ninit c0"); UErrorCode status = U_ZERO_ERROR; - RuleBasedCollator* c0 = (RuleBasedCollator*)Collator::createInstance(status); + RuleBasedCollator* c0 = dynamic_cast(Collator::createInstance(status)); if (U_FAILURE(status)) { errcheckln(status, "Collator::CreateInstance(status) failed with %s", u_errorName(status)); @@ -2333,7 +2333,7 @@ void CollationAPITest::TestClone() { dump("c0", c0, status); logln("\ninit c1"); - RuleBasedCollator* c1 = (RuleBasedCollator*)Collator::createInstance(status); + RuleBasedCollator* c1 = dynamic_cast(Collator::createInstance(status)); c1->setStrength(Collator::TERTIARY); UColAttributeValue val = c1->getAttribute(UCOL_CASE_FIRST, status); if(val == UCOL_LOWER_FIRST){ diff --git a/icu4c/source/test/intltest/callimts.cpp b/icu4c/source/test/intltest/callimts.cpp index bd2ff9c1728..1752b2552f1 100644 --- a/icu4c/source/test/intltest/callimts.cpp +++ b/icu4c/source/test/intltest/callimts.cpp @@ -109,7 +109,7 @@ CalendarLimitTest::TestCalendarExtremeLimit() return; } fmt->adoptCalendar(cal); - ((SimpleDateFormat*) fmt)->applyPattern("HH:mm:ss.SSS Z, EEEE, MMMM d, yyyy G"); + (dynamic_cast(fmt))->applyPattern("HH:mm:ss.SSS Z, EEEE, MMMM d, yyyy G"); // This test used to test the algorithmic limits of the dates that diff --git a/icu4c/source/test/intltest/calregts.cpp b/icu4c/source/test/intltest/calregts.cpp index 8631821651a..ed893c2950d 100644 --- a/icu4c/source/test/intltest/calregts.cpp +++ b/icu4c/source/test/intltest/calregts.cpp @@ -144,7 +144,7 @@ void CalendarRegressionTest::test4100311() { UErrorCode status = U_ZERO_ERROR; - GregorianCalendar *cal = (GregorianCalendar*)Calendar::createInstance(status); + GregorianCalendar *cal = dynamic_cast(Calendar::createInstance(status)); if(U_FAILURE(status)) { dataerrln("Error creating Calendar: %s", u_errorName(status)); delete cal; @@ -620,7 +620,7 @@ void CalendarRegressionTest::dowTest(UBool lenient) if(cal->getActualMinimum(Calendar::DAY_OF_WEEK) != min) { errln("FAIL: actual minimum (Calendar::DAY_OF_WEEK) differs from minimum"); } - if(((Calendar*)cal)->getActualMinimum(UCAL_DAY_OF_WEEK, status) != min) { + if(cal->getActualMinimum(UCAL_DAY_OF_WEEK, status) != min) { errln("FAIL: actual minimum (UCAL_DAY_OF_WEEK, status) differs from minimum"); } // NOTE: This function does not exist! jitterbug #3016 @@ -971,7 +971,7 @@ void CalendarRegressionTest::test4096539() void CalendarRegressionTest::test41003112() { UErrorCode status = U_ZERO_ERROR; - GregorianCalendar *cal = (GregorianCalendar*)Calendar::createInstance(status); + GregorianCalendar *cal = dynamic_cast(Calendar::createInstance(status)); if(U_FAILURE(status)) { dataerrln("Error creating calendar: %s", u_errorName(status)); delete cal; @@ -995,7 +995,7 @@ void CalendarRegressionTest::test4103271() SimpleDateFormat sdf(status); int32_t numYears=40, startYear=1997, numDays=15; UnicodeString output, testDesc, str, str2; - GregorianCalendar *testCal = (GregorianCalendar*)Calendar::createInstance(status); + GregorianCalendar *testCal = dynamic_cast(Calendar::createInstance(status)); if(U_FAILURE(status)) { dataerrln("Error creating calendar: %s", u_errorName(status)); delete testCal; @@ -1459,7 +1459,7 @@ void CalendarRegressionTest::test4118384() void CalendarRegressionTest::test4125881() { UErrorCode status = U_ZERO_ERROR; - LocalPointer cal((GregorianCalendar*) Calendar::createInstance(status), status); + LocalPointer cal(dynamic_cast(Calendar::createInstance(status)), status); if(U_FAILURE(status)) { dataerrln("Error creating calendar %s", u_errorName(status)); return; @@ -1488,7 +1488,7 @@ void CalendarRegressionTest::test4125881() */ void CalendarRegressionTest::test4125892() { UErrorCode status = U_ZERO_ERROR; - LocalPointer cal((GregorianCalendar*) Calendar::createInstance(status), status); + LocalPointer cal(dynamic_cast(Calendar::createInstance(status)), status); if(U_FAILURE(status)) { dataerrln("Error creating calendar %s", u_errorName(status)); return; @@ -2042,7 +2042,7 @@ void CalendarRegressionTest::Test4197699() { int32_t DATA_length = UPRV_LENGTHOF(DATA); UnicodeString str; - DateFormat& dfmt = *(DateFormat*)&fmt; + DateFormat& dfmt = *dynamic_cast(&fmt); for (int32_t i=0; i(Calendar::createInstance(status)); if(U_FAILURE(status)) { errln("Error creating Calendar: %s", u_errorName(status)); delete cal; @@ -3203,7 +3203,7 @@ void CalendarRegressionTest::VerifyNoAssertWithSetGregorianChange(const char* ti if (cal->getDynamicClassID() == GregorianCalendar::getStaticClassID()) { GregorianCalendar* gc = - static_cast(cal.get()); + dynamic_cast(cal.get()); // The beginning of ECMAScript time, namely -(2**53) const double start_of_time = -9007199254740992; gc->setGregorianChange(start_of_time, status); diff --git a/icu4c/source/test/intltest/caltest.cpp b/icu4c/source/test/intltest/caltest.cpp index 2802a999363..0df7a48c558 100644 --- a/icu4c/source/test/intltest/caltest.cpp +++ b/icu4c/source/test/intltest/caltest.cpp @@ -447,8 +447,8 @@ CalendarTest::TestGenericAPI() if (failure(status, "Calendar::createInstance #6")) { return; }else { - ((Calendar *)cal)->roll(UCAL_HOUR, (int32_t)100, status); - ((Calendar *)cal)->clear(UCAL_HOUR); + cal->roll(UCAL_HOUR, (int32_t)100, status); + cal->clear(UCAL_HOUR); #if !UCONFIG_NO_SERVICE URegistryKey key = cal->registerFactory(nullptr, status); cal->unregister(key, status); @@ -3428,10 +3428,10 @@ void CalendarTest::TestIslamicUmAlQura() { Locale umalquraLoc("ar_SA@calendar=islamic-umalqura"); Locale gregoLoc("ar_SA@calendar=gregorian"); TimeZone* tzSA = TimeZone::createTimeZone(UnicodeString(true, zoneSA, -1)); - Calendar* tstCal = Calendar::createInstance(*((const TimeZone *)tzSA), umalquraLoc, status); - Calendar* gregCal = Calendar::createInstance(*((const TimeZone *)tzSA), gregoLoc, status); + Calendar* tstCal = Calendar::createInstance(*tzSA, umalquraLoc, status); + Calendar* gregCal = Calendar::createInstance(*tzSA, gregoLoc, status); - IslamicCalendar* iCal = (IslamicCalendar*)tstCal; + IslamicCalendar* iCal = dynamic_cast(tstCal); if(uprv_strcmp(iCal->getType(), "islamic-umalqura") != 0) { errln("wrong type of calendar created - %s", iCal->getType()); } diff --git a/icu4c/source/test/intltest/canittst.cpp b/icu4c/source/test/intltest/canittst.cpp index fc10d180b0a..41fafb2aa0f 100644 --- a/icu4c/source/test/intltest/canittst.cpp +++ b/icu4c/source/test/intltest/canittst.cpp @@ -248,8 +248,8 @@ UnicodeString CanonicalIteratorTest::getReadable(const UnicodeString &s) { U_CFUNC int U_CALLCONV compareUnicodeStrings(const void *s1, const void *s2) { - UnicodeString **st1 = (UnicodeString **)s1; - UnicodeString **st2 = (UnicodeString **)s2; + UnicodeString **st1 = static_cast(const_cast(s1)); + UnicodeString **st2 = static_cast(const_cast(s2)); return (*st1)->compare(**st2); } @@ -270,7 +270,7 @@ UnicodeString CanonicalIteratorTest::collectionToString(Hashtable *col) { //while (it.hasNext()) while (ne != nullptr) { //String item = (String) it.next(); - UnicodeString *item = (UnicodeString *)(ne->value.pointer); + UnicodeString *item = static_cast(ne->value.pointer); resArray[i++] = item; ne = col->nextElement(el); } diff --git a/icu4c/source/test/intltest/citrtest.cpp b/icu4c/source/test/intltest/citrtest.cpp index 8864b6a85c1..d24f204d19a 100644 --- a/icu4c/source/test/intltest/citrtest.cpp +++ b/icu4c/source/test/intltest/citrtest.cpp @@ -241,7 +241,7 @@ void CharIterTest::TestConstructionAndEquality() { if (*test1 != *test2 || *test1 == *test5) errln("setIndex() failed"); - *((StringCharacterIterator*)test1) = *((StringCharacterIterator*)test3); + *(test1) = *(dynamic_cast(test3)); if (*test1 != *test3 || *test1 == *test5) errln("operator= failed"); diff --git a/icu4c/source/test/intltest/colldata.cpp b/icu4c/source/test/intltest/colldata.cpp index 64cd8b8342e..d989d4f4200 100644 --- a/icu4c/source/test/intltest/colldata.cpp +++ b/icu4c/source/test/intltest/colldata.cpp @@ -238,7 +238,7 @@ U_CDECL_BEGIN static void U_CALLCONV deleteStringList(void *obj) { - StringList *strings = (StringList *) obj; + StringList *strings = static_cast(obj); delete strings; } @@ -301,7 +301,7 @@ void CEToStringsMap::put(uint32_t ce, UnicodeString *string, UErrorCode &status) StringList *CEToStringsMap::getStringList(uint32_t ce) const { - return (StringList *) uhash_iget(map, ce); + return static_cast(uhash_iget(map, ce)); } void CEToStringsMap::putStringList(uint32_t ce, StringList *stringList, UErrorCode &status) diff --git a/icu4c/source/test/intltest/compactdecimalformattest.cpp b/icu4c/source/test/intltest/compactdecimalformattest.cpp index 1fdce822c7a..3a4b1343a90 100644 --- a/icu4c/source/test/intltest/compactdecimalformattest.cpp +++ b/icu4c/source/test/intltest/compactdecimalformattest.cpp @@ -494,7 +494,7 @@ void CompactDecimalFormatTest::TestBug12975() { if (assertSuccess("", status, true, __FILE__, __LINE__)) { UnicodeString resultCdf; cdf->format(12000, resultCdf); - LocalPointer df((DecimalFormat*) DecimalFormat::createInstance(locale, status)); + LocalPointer df(dynamic_cast(DecimalFormat::createInstance(locale, status))); UnicodeString resultDefault; df->format(12000, resultDefault); assertEquals("CompactDecimalFormat should use default pattern when compact pattern is unavailable", diff --git a/icu4c/source/test/intltest/convtest.cpp b/icu4c/source/test/intltest/convtest.cpp index 1e8b86aaf3a..9c2fef3b8a3 100644 --- a/icu4c/source/test/intltest/convtest.cpp +++ b/icu4c/source/test/intltest/convtest.cpp @@ -482,7 +482,7 @@ getUnicodeSetCallback(const void *context, UConverterCallbackReason reason, UErrorCode *pErrorCode) { if(reason<=UCNV_IRREGULAR) { - ((UnicodeSet *)context)->remove(codePoint); // the converter cannot convert this code point + static_cast(const_cast(context))->remove(codePoint); // the converter cannot convert this code point *pErrorCode=U_ZERO_ERROR; // skip } // else ignore the reset, close and clone calls. } diff --git a/icu4c/source/test/intltest/cpdtrtst.cpp b/icu4c/source/test/intltest/cpdtrtst.cpp index 11e7025928c..700cff68a50 100644 --- a/icu4c/source/test/intltest/cpdtrtst.cpp +++ b/icu4c/source/test/intltest/cpdtrtst.cpp @@ -194,7 +194,7 @@ void CompoundTransliteratorTest::TestGetCount(){ UParseError parseError; CompoundTransliterator *ct1=new CompoundTransliterator("Halfwidth-Fullwidth;Fullwidth-Halfwidth", parseError, status); CompoundTransliterator *ct2=new CompoundTransliterator("Any-Hex;Hex-Any;Cyrillic-Latin;Latin-Cyrillic", parseError, status); - CompoundTransliterator *ct3=(CompoundTransliterator*)ct1; + CompoundTransliterator *ct3=ct1; if (U_FAILURE(status)) { dataerrln("FAILED: CompoundTransliterator constructor failed - %s", u_errorName(status)); return; @@ -297,7 +297,7 @@ void CompoundTransliteratorTest::TestGetSetAdoptTransliterator(){ }*/ logln("Testing adoptTransliterator() API of CompoundTransliterator"); UnicodeString ID3("Latin-Katakana"); - Transliterator **transarray2=(Transliterator **)uprv_malloc(sizeof(Transliterator*)*1); + Transliterator **transarray2=static_cast(uprv_malloc(sizeof(Transliterator*)*1)); transarray2[0] = Transliterator::createInstance(ID3,UTRANS_FORWARD,parseError,status); if (transarray2[0] != 0) { ct1->adoptTransliterators(transarray2, 1); diff --git a/icu4c/source/test/intltest/currcoll.cpp b/icu4c/source/test/intltest/currcoll.cpp index fc77c57de14..02fedc58b61 100644 --- a/icu4c/source/test/intltest/currcoll.cpp +++ b/icu4c/source/test/intltest/currcoll.cpp @@ -82,7 +82,7 @@ void CollationCurrencyTest::currencyTest(/*char *par*/) uint32_t i, j; UErrorCode status = U_ZERO_ERROR; Collator::EComparisonResult expectedResult = Collator::EQUAL; - RuleBasedCollator *c = (RuleBasedCollator *)Collator::createInstance("en_US", status); + RuleBasedCollator *c = dynamic_cast(Collator::createInstance("en_US", status)); if (U_FAILURE(status)) { diff --git a/icu4c/source/test/intltest/dtfmrgts.cpp b/icu4c/source/test/intltest/dtfmrgts.cpp index fb3504e7fc0..05ecbc0064c 100644 --- a/icu4c/source/test/intltest/dtfmrgts.cpp +++ b/icu4c/source/test/intltest/dtfmrgts.cpp @@ -80,7 +80,7 @@ void DateFormatRegressionTest::Test4029195(void) UDate today = Calendar::getNow(); logln((UnicodeString) "today: " + today); - SimpleDateFormat *sdf = (SimpleDateFormat*) DateFormat::createDateInstance(); + SimpleDateFormat *sdf = dynamic_cast(DateFormat::createDateInstance()); if (failure(status, "SimpleDateFormat::createDateInstance")) { return; } @@ -518,8 +518,8 @@ void DateFormatRegressionTest::Test4071441(void) } // {sfb} Is it OK to cast away const here? - Calendar *calA = (Calendar*) fmtA->getCalendar(); - Calendar *calB = (Calendar*) fmtB->getCalendar(); + Calendar *calA = const_cast(fmtA->getCalendar()); + Calendar *calB = const_cast(fmtB->getCalendar()); if(!calA || !calB) { errln("Couldn't get proper calendars, exiting"); delete fmtA; @@ -1140,7 +1140,7 @@ void DateFormatRegressionTest::Test4182066(void) { actStr.append("null"); } else { // Yuck: See j25 - ((DateFormat*)&dispFmt)->format(actual, actStr); + (dynamic_cast(&dispFmt))->format(actual, actStr); } if (expected == actual) { @@ -1151,7 +1151,7 @@ void DateFormatRegressionTest::Test4182066(void) { expStr.append("null"); } else { // Yuck: See j25 - ((DateFormat*)&dispFmt)->format(expected, expStr); + (dynamic_cast(&dispFmt))->format(expected, expStr); } out.append("FAIL: " + str + " => " + actStr + ", expected " + expStr + "\n"); @@ -1175,13 +1175,13 @@ DateFormatRegressionTest::Test4210209(void) { UnicodeString pattern("MMM d, yyyy"); SimpleDateFormat sfmt(pattern, Locale::getUS(), status); SimpleDateFormat sdisp("MMM dd yyyy GG", Locale::getUS(), status); - DateFormat& fmt = *(DateFormat*)&sfmt; // Yuck: See j25 - DateFormat& disp = *(DateFormat*)&sdisp; // Yuck: See j25 + DateFormat& fmt = *dynamic_cast(&sfmt); // Yuck: See j25 + DateFormat& disp = *dynamic_cast(&sdisp); // Yuck: See j25 if (U_FAILURE(status)) { dataerrln("Couldn't create SimpleDateFormat - %s", u_errorName(status)); return; } - Calendar* calx = (Calendar*)fmt.getCalendar(); // cast away const! + Calendar* calx = const_cast(fmt.getCalendar()); // cast away const! calx->setLenient(false); UDate d = date(2000-1900, UCAL_FEBRUARY, 29); UnicodeString s, ss; diff --git a/icu4c/source/test/intltest/dtfmtrtts.cpp b/icu4c/source/test/intltest/dtfmtrtts.cpp index cbad61a6ef8..0da9c04d18b 100644 --- a/icu4c/source/test/intltest/dtfmtrtts.cpp +++ b/icu4c/source/test/intltest/dtfmtrtts.cpp @@ -297,7 +297,7 @@ void DateFormatRoundTripTest::test(DateFormat *fmt, const Locale &origLocale, UB } //logln(UnicodeString("Min date is ") + fullFormat(minDate) + " for " + origLocale.getName()); - pat = ((SimpleDateFormat*)fmt)->toPattern(pat); + pat = dynamic_cast(fmt)->toPattern(pat); // NOTE TO MAINTAINER // This indexOf check into the pattern needs to be refined to ignore diff --git a/icu4c/source/test/intltest/dtfmttst.cpp b/icu4c/source/test/intltest/dtfmttst.cpp index 22f4147ab87..9d86d2d804d 100644 --- a/icu4c/source/test/intltest/dtfmttst.cpp +++ b/icu4c/source/test/intltest/dtfmttst.cpp @@ -715,7 +715,7 @@ DateFormatTest::tryPat994(SimpleDateFormat* format, const char* pat, const char* else { UnicodeString f; - ((DateFormat*)format)->format(date, f); + (dynamic_cast(format))->format(date, f); logln(UnicodeString(" parse(") + str + ") -> " + dateToString(date)); logln((UnicodeString)" format -> " + f); if (expected == null || @@ -753,12 +753,12 @@ DateFormatTest::TestRunTogetherPattern985() return; } UDate date1 = Calendar::getNow(); - ((DateFormat*)formatter)->format(date1, now); + (dynamic_cast(formatter))->format(date1, now); logln(now); ParsePosition pos(0); UDate date2 = formatter->parse(now, pos); if (date2 == 0) then = UnicodeString("Parse stopped at ") + pos.getIndex(); - else ((DateFormat*)formatter)->format(date2, then); + else (dynamic_cast(formatter))->format(date2, then); logln(then); if (!(date2 == date1)) errln((UnicodeString)"FAIL"); delete formatter; @@ -803,7 +803,7 @@ DateFormatTest::testIt917(SimpleDateFormat* fmt, UnicodeString& str, UDate expec logln((UnicodeString)"pattern=" + fmt->toPattern(pattern) + " string=" + str); Formattable o; //try { - ((Format*)fmt)->parseObject(str, o, status); + dynamic_cast(fmt)->parseObject(str, o, status); //} if (U_FAILURE(status)) return; //catch(ParseException e) { @@ -812,7 +812,8 @@ DateFormatTest::testIt917(SimpleDateFormat* fmt, UnicodeString& str, UDate expec //} logln((UnicodeString)"Parsed object: " + dateToString(o.getDate())); if (!(o.getDate() == expected)) errln((UnicodeString)"FAIL: Expected " + dateToString(expected)); - UnicodeString formatted; ((Format*)fmt)->format(o, formatted, status); + UnicodeString formatted; + fmt->format(o, formatted, status); logln((UnicodeString)"Formatted string: " + formatted); if (!(formatted == str)) errln((UnicodeString)"FAIL: Expected " + str); if (U_FAILURE(status)) errln((UnicodeString)"FAIL: UErrorCode received during test: " + (int32_t)status); @@ -835,7 +836,7 @@ DateFormatTest::TestCzechMonths459() } UnicodeString pattern; - logln((UnicodeString)"Pattern " + ((SimpleDateFormat*) fmt)->toPattern(pattern)); + logln((UnicodeString)"Pattern " + (dynamic_cast(fmt))->toPattern(pattern)); UDate june = date(97, UCAL_JUNE, 15); UDate july = date(97, UCAL_JULY, 15); UnicodeString juneStr; fmt->format(june, juneStr); @@ -911,7 +912,7 @@ DateFormatTest::TestDayOfYearPattern195() int32_t year,month,day,hour,min,sec; dateToFields(today,year,month,day,hour,min,sec); UDate expected = date(year, month, day); logln((UnicodeString)"Test Date: " + dateToString(today)); - SimpleDateFormat* sdf = (SimpleDateFormat*)DateFormat::createDateInstance(); + SimpleDateFormat* sdf = dynamic_cast(DateFormat::createDateInstance()); if (sdf == nullptr){ dataerrln("Error calling DateFormat::createDateInstance()"); return; @@ -931,13 +932,13 @@ DateFormatTest::tryPattern(SimpleDateFormat& sdf, UDate d, const char* pattern, if (pattern != 0) sdf.applyPattern(pattern); UnicodeString thePat; logln((UnicodeString)"pattern: " + sdf.toPattern(thePat)); - UnicodeString formatResult; (*(DateFormat*)&sdf).format(d, formatResult); + UnicodeString formatResult; (*dynamic_cast(&sdf)).format(d, formatResult); logln((UnicodeString)" format -> " + formatResult); // try { UDate d2 = sdf.parse(formatResult, status); logln((UnicodeString)" parse(" + formatResult + ") -> " + dateToString(d2)); if (d2 != expected) errln((UnicodeString)"FAIL: Expected " + dateToString(expected)); - UnicodeString format2; (*(DateFormat*)&sdf).format(d2, format2); + UnicodeString format2; (*dynamic_cast(&sdf)).format(d2, format2); logln((UnicodeString)" format -> " + format2); if (!(formatResult == format2)) errln((UnicodeString)"FAIL: Round trip drift"); //} @@ -963,7 +964,7 @@ DateFormatTest::TestQuotePattern161() return; } UDate currentTime_1 = date(97, UCAL_AUGUST, 13, 10, 42, 28); - UnicodeString dateString; ((DateFormat*)formatter)->format(currentTime_1, dateString); + UnicodeString dateString; (dynamic_cast(formatter))->format(currentTime_1, dateString); UnicodeString exp("08/13/1997 at 10:42:28 AM "); logln((UnicodeString)"format(" + dateToString(currentTime_1) + ") = " + dateString); if (0 != dateString.compareBetween(0, exp.length(), exp, 0, exp.length())) errln((UnicodeString)"FAIL: Expected " + exp); @@ -1145,7 +1146,7 @@ DateFormatTest::TestBadInput135a() } else { UnicodeString result; - ((DateFormat*)dateParse)->format(date, result); + (dynamic_cast(dateParse))->format(date, result); logln((UnicodeString)"Parsed \"" + s + "\" using \"" + dateParse->toPattern(thePat) + "\" to: " + result); if (expected == 0) errln((UnicodeString)"FAIL: Expected parse failure, got " + result); @@ -1196,7 +1197,7 @@ DateFormatTest::parse2DigitYear(DateFormat& fmt, const char* str, UDate expected //try { UDate d = fmt.parse(str, status); UnicodeString thePat; - logln(UnicodeString("Parsing \"") + str + "\" with " + ((SimpleDateFormat*)&fmt)->toPattern(thePat) + + logln(UnicodeString("Parsing \"") + str + "\" with " + (dynamic_cast(&fmt))->toPattern(thePat) + " => " + dateToString(d)); if (d != expected) errln((UnicodeString)"FAIL: Expected " + expected); //} @@ -4475,7 +4476,7 @@ void DateFormatTest::TestFormatsWithNumberSystems() dataerrln("Calendar::setTime fails for locale %s, date %.1f, status %s", itemPtr->localeID, date, u_errorName(status)); continue; } - LocalPointer sdfmt(static_cast(DateFormat::createDateInstance(itemPtr->style, locale))); + LocalPointer sdfmt(dynamic_cast(DateFormat::createDateInstance(itemPtr->style, locale))); if (sdfmt.isNull()) { dataerrln("DateFormat::createDateInstance fails for locale %s", itemPtr->localeID); continue; @@ -4558,7 +4559,7 @@ UBool DateFormatTest::showParse(DateFormat &format, const UnicodeString &formatt UDate parsed = format.parse(formattedString, parsePosition); UBool ok = TEST_DATE == parsed && parsePosition.getIndex() == formattedString.length(); UnicodeString pattern; - static_cast(format).toPattern(pattern); + dynamic_cast(format).toPattern(pattern); if (ok) { logln(pattern + " parsed: " + formattedString); } else { @@ -4705,7 +4706,7 @@ void DateFormatTest::TestParseMultiPatternMatch() { for (itemPtr = items; itemPtr->parseString != "--end--"; itemPtr++ ) { status = U_ZERO_ERROR; ParsePosition pos(0); - ((SimpleDateFormat*) sdmft)->applyPattern(itemPtr->pattern); + (dynamic_cast(sdmft))->applyPattern(itemPtr->pattern); if (U_FAILURE(status)) { dataerrln("Unable to create SimpleDateFormat - %s", u_errorName(status)); continue; @@ -5053,7 +5054,7 @@ void DateFormatTest::TestPatternFromSkeleton() { return; } UnicodeString pattern; - static_cast(fmt.getAlias())->toPattern(pattern); + dynamic_cast(fmt.getAlias())->toPattern(pattern); assertEquals("Format pattern", TESTDATA[i].pattern, pattern); } } diff --git a/icu4c/source/test/intltest/dtifmtts.cpp b/icu4c/source/test/intltest/dtifmtts.cpp index 945459244b5..f474bff44ce 100644 --- a/icu4c/source/test/intltest/dtifmtts.cpp +++ b/icu4c/source/test/intltest/dtifmtts.cpp @@ -327,7 +327,7 @@ void DateIntervalFormatTest::testAPI() { Formattable fmttable; status = U_ZERO_ERROR; // TODO: why do I need cast? - ((Format*)dtitvfmt)->parseObject(res, fmttable, status); + (dynamic_cast(dtitvfmt))->parseObject(res, fmttable, status); if ( status != U_INVALID_FORMAT_ERROR ) { dataerrln("ERROR: parse should set U_INVALID_FORMAT_ERROR - exiting"); return; @@ -1775,7 +1775,7 @@ void DateIntervalFormatTest::testTicket11985() { return; } UnicodeString pattern; - static_cast(fmt->getDateFormat())->toPattern(pattern); + dynamic_cast(fmt->getDateFormat())->toPattern(pattern); assertEquals("Format pattern", u"h:mm\u202Fa", pattern); } diff --git a/icu4c/source/test/intltest/dtptngts.cpp b/icu4c/source/test/intltest/dtptngts.cpp index 1fa1a8b19f7..d2a2ebf9cd0 100644 --- a/icu4c/source/test/intltest/dtptngts.cpp +++ b/icu4c/source/test/intltest/dtptngts.cpp @@ -539,8 +539,8 @@ void IntlTestDateTimePatternGeneratorAPI::testAPI(/*char *par*/) delete format; // get a pattern and modify it - format = (SimpleDateFormat *)DateFormat::createDateTimeInstance(DateFormat::kFull, DateFormat::kFull, - deLocale); + format = dynamic_cast(DateFormat::createDateTimeInstance(DateFormat::kFull, DateFormat::kFull, + deLocale)); format->setTimeZone(*zone); UnicodeString pattern; pattern = format->toPattern(pattern); @@ -751,8 +751,8 @@ void IntlTestDateTimePatternGeneratorAPI::testAPI(/*char *par*/) delete patGen; return; } - SimpleDateFormat *enFormat = (SimpleDateFormat *)DateFormat::createDateTimeInstance(DateFormat::kFull, - DateFormat::kFull, Locale::getEnglish()); + SimpleDateFormat *enFormat = dynamic_cast(DateFormat::createDateTimeInstance(DateFormat::kFull, + DateFormat::kFull, Locale::getEnglish())); enFormat->setTimeZone(*enZone); while (patternTests2[dataIndex].length() > 0) { logln(patternTests2[dataIndex]); @@ -844,7 +844,7 @@ void IntlTestDateTimePatternGeneratorAPI::testAPI(/*char *par*/) ptrSkeletonEnum->reset(status); count=ptrSkeletonEnum->count(status); for (i=0; isnext(status); + ptrSkeleton = const_cast(ptrSkeletonEnum->snext(status)); returnPattern = test->getPatternForSkeleton(*ptrSkeleton); if ( returnPattern != testSkeletonsResults[i] ) { errln(UnicodeString("ERROR: Unexpected result from getSkeletons and getPatternForSkeleton\nGot: ") + returnPattern @@ -858,7 +858,7 @@ void IntlTestDateTimePatternGeneratorAPI::testAPI(/*char *par*/) } count=ptrBaseSkeletonEnum->count(status); for (i=0; isnext(status); + ptrSkeleton = const_cast(ptrBaseSkeletonEnum->snext(status)); if ( *ptrSkeleton != testBaseSkeletonsResults[i] ) { errln("ERROR: Unexpected result from getBaseSkeletons() !\n"); } diff --git a/icu4c/source/test/intltest/g7coll.cpp b/icu4c/source/test/intltest/g7coll.cpp index b2a26cecf68..8ef4fd7188c 100644 --- a/icu4c/source/test/intltest/g7coll.cpp +++ b/icu4c/source/test/intltest/g7coll.cpp @@ -111,7 +111,7 @@ void G7CollationTest::TestG7Locales(/* char* par */) continue; } - const UnicodeString &rules = ((RuleBasedCollator*)myCollation.getAlias())->getRules(); + const UnicodeString &rules = (dynamic_cast(myCollation.getAlias()))->getRules(); if (rules.isEmpty() && (locale == Locale::getCanadaFrench() || locale == Locale::getJapanese())) { dataerrln("%s Collator missing rule string", locale.getName()); @@ -156,7 +156,7 @@ void G7CollationTest::TestDemo1(/* char* par */) errcheckln(status, "Couldn't instantiate collator. Error: %s", u_errorName(status)); return; } - const UnicodeString baseRules = ((RuleBasedCollator*)col)->getRules(); + const UnicodeString baseRules = (dynamic_cast(col))->getRules(); UnicodeString newRules(" & Z < p, P"); newRules.insert(0, baseRules); RuleBasedCollator *myCollation = new RuleBasedCollator(newRules, status); @@ -190,7 +190,7 @@ void G7CollationTest::TestDemo2(/* char* par */) errcheckln(status, "Couldn't instantiate collator. Error: %s", u_errorName(status)); return; } - const UnicodeString baseRules = ((RuleBasedCollator*)col)->getRules(); + const UnicodeString baseRules = (dynamic_cast(col))->getRules(); UnicodeString newRules("& C < ch , cH, Ch, CH"); newRules.insert(0, baseRules); RuleBasedCollator *myCollation = new RuleBasedCollator(newRules, status); @@ -224,7 +224,7 @@ void G7CollationTest::TestDemo3(/* char* par */) delete col; return; } - const UnicodeString baseRules = ((RuleBasedCollator*)col)->getRules(); + const UnicodeString baseRules = (dynamic_cast(col))->getRules(); UnicodeString newRules = "& Question'-'mark ; '?' & Hash'-'mark ; '#' & Ampersand ; '&'"; newRules.insert(0, baseRules); RuleBasedCollator *myCollation = new RuleBasedCollator(newRules, status); @@ -259,7 +259,7 @@ void G7CollationTest::TestDemo4(/* char* par */) return; } - const UnicodeString baseRules = ((RuleBasedCollator*)col)->getRules(); + const UnicodeString baseRules = (dynamic_cast(col))->getRules(); UnicodeString newRules = " & aa ; a'-' & ee ; e'-' & ii ; i'-' & oo ; o'-' & uu ; u'-' "; newRules.insert(0, baseRules); RuleBasedCollator *myCollation = new RuleBasedCollator(newRules, status); diff --git a/icu4c/source/test/intltest/icusvtst.cpp b/icu4c/source/test/intltest/icusvtst.cpp index 6e35dabd386..a5e60bc4db1 100644 --- a/icu4c/source/test/intltest/icusvtst.cpp +++ b/icu4c/source/test/intltest/icusvtst.cpp @@ -89,7 +89,7 @@ class Integer : public UObject { virtual bool operator==(const UObject& other) const { return typeid(*this) == typeid(other) && - _val == ((Integer&)other)._val; + _val == (dynamic_cast(const_cast(other)))._val; } public: @@ -127,7 +127,7 @@ class TestIntegerService : public ICUService { } virtual UObject* cloneInstance(UObject* instance) const override { - return instance ? new Integer(*(Integer*)instance) : nullptr; + return instance ? new Integer(*dynamic_cast(instance)) : nullptr; } }; @@ -315,7 +315,7 @@ void ICUServiceTest::msgstr(const UnicodeString& message, UObject* obj, UBool err) { if (obj) { - UnicodeString* str = (UnicodeString*)obj; + UnicodeString* str = dynamic_cast(obj); logln(message + *str); delete str; } else if (err) { @@ -337,7 +337,7 @@ ICUServiceTest::testAPI_One() service.registerInstance(singleton0, "en_US", status); { UErrorCode status = U_ZERO_ERROR; - Integer* result = (Integer*)service.get("en_US_FOO", status); + Integer* result = dynamic_cast(service.get("en_US_FOO", status)); confirmEqual("1) en_US_FOO -> en_US", result, singleton0); delete result; } @@ -349,7 +349,7 @@ ICUServiceTest::testAPI_One() service.registerInstance(singleton1, "en_US_FOO", status); { UErrorCode status = U_ZERO_ERROR; - Integer* result = (Integer*)service.get("en_US_FOO", status); + Integer* result = dynamic_cast(service.get("en_US_FOO", status)); confirmEqual("2) en_US_FOO -> en_US_FOO", result, singleton1); delete result; } @@ -357,7 +357,7 @@ ICUServiceTest::testAPI_One() // search for an object that falls back to the first registered locale { UErrorCode status = U_ZERO_ERROR; - Integer* result = (Integer*)service.get("en_US_BAR", status); + Integer* result = dynamic_cast(service.get("en_US_BAR", status)); confirmEqual("3) en_US_BAR -> en_US", result, singleton0); delete result; } @@ -379,7 +379,7 @@ ICUServiceTest::testAPI_One() // search for en_US should still find en_US object { UErrorCode status = U_ZERO_ERROR; - Integer* result = (Integer*)service.get("en_US_BAR", status); + Integer* result = dynamic_cast(service.get("en_US_BAR", status)); confirmEqual("6) en_US_BAR -> en_US", result, singleton0); delete result; } @@ -394,7 +394,7 @@ ICUServiceTest::testAPI_One() // should get data from that new factory { UErrorCode status = U_ZERO_ERROR; - Integer* result = (Integer*)service.get("en_US_BAR", status); + Integer* result = dynamic_cast(service.get("en_US_BAR", status)); confirmEqual("10) en_US_BAR -> (3)", result, singleton3); delete result; } @@ -411,7 +411,7 @@ ICUServiceTest::testAPI_One() // should get original data again after remove factory { UErrorCode status = U_ZERO_ERROR; - Integer* result = (Integer*)service.get("en_US_BAR", status); + Integer* result = dynamic_cast(service.get("en_US_BAR", status)); confirmEqual("12) en_US_BAR -> (3)", result, singleton0); delete result; } @@ -419,7 +419,7 @@ ICUServiceTest::testAPI_One() // shouldn't find unregistered ids { UErrorCode status = U_ZERO_ERROR; - Integer* result = (Integer*)service.get("foo", status); + Integer* result = dynamic_cast(service.get("foo", status)); confirmIdentical("13) foo -> null", result, nullptr); delete result; } @@ -428,7 +428,7 @@ ICUServiceTest::testAPI_One() { UnicodeString resultID; UErrorCode status = U_ZERO_ERROR; - Integer* result = (Integer*)service.get("EN_us_fOo", &resultID, status); + Integer* result = dynamic_cast(service.get("EN_us_fOo", &resultID, status)); confirmEqual("14a) find-non-canonical", result, singleton1); confirmStringsEqual("14b) find non-canonical", resultID, "en_US_FOO"); delete result; @@ -440,7 +440,7 @@ ICUServiceTest::testAPI_One() { UnicodeString resultID; UErrorCode status = U_ZERO_ERROR; - Integer* result = (Integer*)service.get("En_Ca_DuDe", &resultID, status); + Integer* result = dynamic_cast(service.get("En_Ca_DuDe", &resultID, status)); confirmEqual("15a) find-non-canonical", result, singleton4); confirmStringsEqual("15b) register non-canonical", resultID, "en_CA_DUDE"); delete result; @@ -453,7 +453,7 @@ ICUServiceTest::testAPI_One() service.registerInstance(singleton5, "en_US_BAR", false, status); { UErrorCode status = U_ZERO_ERROR; - Integer* result = (Integer*)service.get("en_US_BAR", status); + Integer* result = dynamic_cast(service.get("en_US_BAR", status)); confirmEqual("17) get invisible", result, singleton5); delete result; } @@ -491,7 +491,7 @@ public: } virtual UObject* cloneInstance(UObject* instance) const override { - return instance ? new UnicodeString(*(UnicodeString*)instance) : nullptr; + return instance ? new UnicodeString(*dynamic_cast(instance)) : nullptr; } }; @@ -511,7 +511,7 @@ class TestStringService : public ICUService { } virtual UObject* cloneInstance(UObject* instance) const override { - return instance ? new UnicodeString(*(UnicodeString*)instance) : nullptr; + return instance ? new UnicodeString(*dynamic_cast(instance)) : nullptr; } }; @@ -584,7 +584,7 @@ class TestMultipleKeyStringFactory : public ICUServiceFactory { void updateVisibleIDs(Hashtable& result, UErrorCode& status) const override { if (U_SUCCESS(_status)) { for (int32_t i = 0; i < _ids.size(); ++i) { - result.put(*(UnicodeString*)_ids[i], (void*)this, status); + result.put(*static_cast(_ids[i]), (void*)this, status); } } } @@ -633,7 +633,7 @@ ICUServiceTest::testAPI_Two() { UErrorCode status = U_ZERO_ERROR; const UnicodeString en_US = "en_US"; - UnicodeString* result = (UnicodeString*)service.get(en_US, status); + UnicodeString* result = dynamic_cast(service.get(en_US, status)); confirmEqual("21) locale", result, &en_US); delete result; } @@ -643,7 +643,7 @@ ICUServiceTest::testAPI_Two() UErrorCode status = U_ZERO_ERROR; const UnicodeString en_US_BAR = "en_US_BAR"; UnicodeString resultID; - UnicodeString* result = (UnicodeString*)service.get("EN_us_bar", &resultID, status); + UnicodeString* result = dynamic_cast(service.get("EN_us_bar", &resultID, status)); confirmEqual("22) locale", &resultID, &en_US_BAR); delete result; } @@ -653,7 +653,7 @@ ICUServiceTest::testAPI_Two() service.registerInstance(singleton0, "en_US_BAR", status); { UErrorCode status = U_ZERO_ERROR; - UnicodeString* result = (UnicodeString*)service.get("en_US_BAR", status); + UnicodeString* result = dynamic_cast(service.get("en_US_BAR", status)); confirmEqual("23) override super", result, singleton0); delete result; } @@ -662,7 +662,7 @@ ICUServiceTest::testAPI_Two() service.reset(); { UErrorCode status = U_ZERO_ERROR; - UnicodeString* result = (UnicodeString*)service.get("en_US", status); + UnicodeString* result = dynamic_cast(service.get("en_US", status)); confirmIdentical("24) empty", result, nullptr); } @@ -686,8 +686,8 @@ ICUServiceTest::testAPI_Two() UVector ids(uprv_deleteUObject, uhash_compareUnicodeString, 0, status); service.getVisibleIDs(ids, status); for (int i = 0; i < ids.size(); ++i) { - const UnicodeString* id = (const UnicodeString*)ids[i]; - UnicodeString* result = (UnicodeString*)service.get(*id, status); + const UnicodeString* id = static_cast(const_cast(ids[i])); + UnicodeString* result = dynamic_cast(service.get(*id, status)); if (result) { logln(" " + *id + " --> " + *result); delete result; @@ -705,7 +705,7 @@ ICUServiceTest::testAPI_Two() UVector names(status); service.getDisplayNames(names, status); for (int i = 0; i < names.size(); ++i) { - const StringPair* pair = (const StringPair*)names[i]; + const StringPair* pair = static_cast(names[i]); logln(" " + pair->displayName + " --> " + pair->id); } confirmIdentical("26) display names", names.size(), 4); @@ -745,7 +745,7 @@ ICUServiceTest::testAPI_Two() UVector names(status); service.getDisplayNames(names, Locale("es"), status); for (int i = 0; i < names.size(); ++i) { - const StringPair* pair = (const StringPair*)names[i]; + const StringPair* pair = static_cast(names[i]); logln(" " + pair->displayName + " --> " + pair->id); } confirmIdentical("29) display names", names.size(), 7); @@ -757,7 +757,7 @@ ICUServiceTest::testAPI_Two() UErrorCode status = U_ZERO_ERROR; UnicodeString actualID; UnicodeString id = "en_us_surfer_gal"; - UnicodeString* gal = (UnicodeString*)service.get(id, &actualID, status); + UnicodeString* gal = dynamic_cast(service.get(id, &actualID, status)); if (gal != nullptr) { UnicodeString displayName; logln("actual id: " + actualID); @@ -780,7 +780,7 @@ ICUServiceTest::testAPI_Two() UErrorCode status = U_ZERO_ERROR; UnicodeString actualID; UnicodeString id = "en_US_SURFER_BOZO"; - UnicodeString* bozo = (UnicodeString*)service.get(id, &actualID, status); + UnicodeString* bozo = dynamic_cast(service.get(id, &actualID, status)); if (bozo != nullptr) { UnicodeString displayName; service.getDisplayName(actualID, displayName, Locale::getEnglish()); @@ -807,7 +807,7 @@ ICUServiceTest::testAPI_Two() UVector ids(uprv_deleteUObject, uhash_compareUnicodeString, 0, status); service.getVisibleIDs(ids, status); for (int i = 0; i < ids.size(); ++i) { - const UnicodeString* id = (const UnicodeString*)ids[i]; + const UnicodeString* id = static_cast(const_cast(ids[i])); msgstr(*id + "? ", service.get(*id, status)); } @@ -904,7 +904,7 @@ ICUServiceTest::testRBF() service.getVisibleIDs(ids, status); logln("all visible ids:"); for (int i = 0; i < ids.size(); ++i) { - const UnicodeString* id = (const UnicodeString*)ids[i]; + const UnicodeString* id = static_cast(const_cast(ids[i])); logln(*id); } } @@ -917,7 +917,7 @@ ICUServiceTest::testRBF() service.getDisplayNames(names, Locale::getGermany(), status); logln("service display names for de_DE"); for (int i = 0; i < names.size(); ++i) { - const StringPair* pair = (const StringPair*)names[i]; + const StringPair* pair = static_cast(names[i]); logln(" " + pair->displayName + " --> " + pair->id); } } @@ -942,7 +942,7 @@ ICUServiceTest::testRBF() UVector names(status); service.getDisplayNames(names, idNames[i], status); for (int i = 0; i < names.size(); ++i) { - const StringPair* pair = (const StringPair*)names[i]; + const StringPair* pair = static_cast(names[i]); logln(" " + pair->displayName + " --> " + pair->id); } } @@ -986,7 +986,7 @@ ICUServiceTest::testNotification() logln("registering bar... "); ls.registerInstance(new UnicodeString("Bar"), "en_BAR", status); logln("getting foo..."); - UnicodeString* result = (UnicodeString*)ls.get("en_FOO", status); + UnicodeString* result = dynamic_cast(ls.get("en_FOO", status)); logln(*result); delete result; @@ -1031,7 +1031,7 @@ public void serviceChanged(ICUService s) { class TestStringLocaleService : public ICULocaleService { public: virtual UObject* cloneInstance(UObject* instance) const override { - return instance ? new UnicodeString(*(UnicodeString*)instance) : nullptr; + return instance ? new UnicodeString(*dynamic_cast(instance)) : nullptr; } }; @@ -1053,21 +1053,21 @@ void ICUServiceTest::testLocale() { { UErrorCode status = U_ZERO_ERROR; - UnicodeString* target = (UnicodeString*)service.get("de_US", status); + UnicodeString* target = dynamic_cast(service.get("de_US", status)); confirmEqual("test de_US", german, target); delete target; } { UErrorCode status = U_ZERO_ERROR; - UnicodeString* target = (UnicodeString*)service.get("de_US", LocaleKey::KIND_ANY, status); + UnicodeString* target = dynamic_cast(service.get("de_US", LocaleKey::KIND_ANY, status)); confirmEqual("test de_US 2", german, target); delete target; } { UErrorCode status = U_ZERO_ERROR; - UnicodeString* target = (UnicodeString*)service.get("de_US", 1234, status); + UnicodeString* target = dynamic_cast(service.get("de_US", 1234, status)); confirmEqual("test de_US 3", german, target); delete target; } @@ -1075,7 +1075,7 @@ void ICUServiceTest::testLocale() { { UErrorCode status = U_ZERO_ERROR; Locale actualReturn; - UnicodeString* target = (UnicodeString*)service.get("de_US", &actualReturn, status); + UnicodeString* target = dynamic_cast(service.get("de_US", &actualReturn, status)); confirmEqual("test de_US 5", german, target); confirmEqual("test de_US 6", &actualReturn, &Locale::getGerman()); delete target; @@ -1084,7 +1084,7 @@ void ICUServiceTest::testLocale() { { UErrorCode status = U_ZERO_ERROR; Locale actualReturn; - UnicodeString* target = (UnicodeString*)service.get("de_US", LocaleKey::KIND_ANY, &actualReturn, status); + UnicodeString* target = dynamic_cast(service.get("de_US", LocaleKey::KIND_ANY, &actualReturn, status)); confirmEqual("test de_US 7", &actualReturn, &Locale::getGerman()); delete target; } @@ -1092,7 +1092,7 @@ void ICUServiceTest::testLocale() { { UErrorCode status = U_ZERO_ERROR; Locale actualReturn; - UnicodeString* target = (UnicodeString*)service.get("de_US", 1234, &actualReturn, status); + UnicodeString* target = dynamic_cast(service.get("de_US", 1234, &actualReturn, status)); confirmEqual("test de_US 8", german, target); confirmEqual("test de_US 9", &actualReturn, &Locale::getGerman()); delete target; @@ -1106,21 +1106,21 @@ void ICUServiceTest::testLocale() { { UErrorCode status = U_ZERO_ERROR; - UnicodeString* target = (UnicodeString*)service.get("de_US", 1, status); + UnicodeString* target = dynamic_cast(service.get("de_US", 1, status)); confirmEqual("test de_US kind 1", one, target); delete target; } { UErrorCode status = U_ZERO_ERROR; - UnicodeString* target = (UnicodeString*)service.get("de_US", 2, status); + UnicodeString* target = dynamic_cast(service.get("de_US", 2, status)); confirmEqual("test de_US kind 2", two, target); delete target; } { UErrorCode status = U_ZERO_ERROR; - UnicodeString* target = (UnicodeString*)service.get("de_US", status); + UnicodeString* target = dynamic_cast(service.get("de_US", status)); confirmEqual("test de_US kind 3", german, target); delete target; } @@ -1150,7 +1150,7 @@ void ICUServiceTest::testLocale() { { UErrorCode status = U_ZERO_ERROR; - UnicodeString* target = (UnicodeString*)service.get("za_PPP", status); + UnicodeString* target = dynamic_cast(service.get("za_PPP", status)); confirmEqual("test zappp", root, target); delete target; } @@ -1159,7 +1159,7 @@ void ICUServiceTest::testLocale() { Locale::setDefault(Locale::getJapanese(), status); { UErrorCode status = U_ZERO_ERROR; - UnicodeString* target = (UnicodeString*)service.get("za_PPP", status); + UnicodeString* target = dynamic_cast(service.get("za_PPP", status)); confirmEqual("test with ja locale", japanese, target); delete target; } @@ -1170,7 +1170,7 @@ void ICUServiceTest::testLocale() { service.getVisibleIDs(ids, status); logln("all visible ids:"); for (int i = 0; i < ids.size(); ++i) { - const UnicodeString* id = (const UnicodeString*)ids[i]; + const UnicodeString* id = static_cast(const_cast(ids[i])); logln(*id); } } @@ -1182,14 +1182,14 @@ void ICUServiceTest::testLocale() { service.getVisibleIDs(ids, status); logln("all visible ids:"); for (int i = 0; i < ids.size(); ++i) { - const UnicodeString* id = (const UnicodeString*)ids[i]; + const UnicodeString* id = static_cast(const_cast(ids[i])); logln(*id); } } { UErrorCode status = U_ZERO_ERROR; - UnicodeString* target = (UnicodeString*)service.get("za_PPP", status); + UnicodeString* target = dynamic_cast(service.get("za_PPP", status)); confirmEqual("test with en locale", root, target); delete target; } @@ -1232,7 +1232,7 @@ class WrapFactory : public ICUServiceFactory { if (U_SUCCESS(status)) { UnicodeString temp; if (key.currentID(temp).compare(getGreetingID()) == 0) { - UnicodeString* previous = (UnicodeString*)service->getKey((ICUServiceKey&)key, nullptr, this, status); + UnicodeString* previous = dynamic_cast(service->getKey(const_cast(key), nullptr, this, status)); if (previous) { previous->insert(0, "A different greeting: \""); previous->append("\""); @@ -1286,7 +1286,7 @@ ICUServiceTest::testWrapFactory() { UErrorCode status = U_ZERO_ERROR; - UnicodeString* result = (UnicodeString*)service.get(greetingID, status); + UnicodeString* result = dynamic_cast(service.get(greetingID, status)); if (result) { logln("test one: " + *result); delete result; @@ -1296,7 +1296,7 @@ ICUServiceTest::testWrapFactory() service.registerFactory(new WrapFactory(), status); { UErrorCode status = U_ZERO_ERROR; - UnicodeString* result = (UnicodeString*)service.get(greetingID, status); + UnicodeString* result = dynamic_cast(service.get(greetingID, status)); UnicodeString target = "A different greeting: \"Hello There\""; confirmEqual("wrap test: ", result, &target); delete result; @@ -1342,7 +1342,7 @@ void ICUServiceTest::testCoverage() service.registerFactory(sf, status); { - UnicodeString* result = (UnicodeString*)service.get("object", status); + UnicodeString* result = dynamic_cast(service.get("object", status)); if (result) { logln("object is: " + *result); delete result; @@ -1361,7 +1361,7 @@ void ICUServiceTest::testCoverage() TestStringSimpleKeyService service; service.registerInstance(howdy, "Greetings", status); { - UnicodeString* result = (UnicodeString*)service.get("Greetings", status); + UnicodeString* result = dynamic_cast(service.get("Greetings", status)); if (result) { logln("object is: " + *result); delete result; diff --git a/icu4c/source/test/intltest/itercoll.cpp b/icu4c/source/test/intltest/itercoll.cpp index 3b6465d051f..5c41ac963ea 100644 --- a/icu4c/source/test/intltest/itercoll.cpp +++ b/icu4c/source/test/intltest/itercoll.cpp @@ -26,7 +26,7 @@ CollationIteratorTest::CollationIteratorTest() : test1("What subset of all possible test cases?", ""), test2("has the highest probability of detecting", "") { - en_us = (RuleBasedCollator *)Collator::createInstance(Locale::getUS(), status); + en_us = dynamic_cast(Collator::createInstance(Locale::getUS(), status)); if(U_FAILURE(status)) { delete en_us; en_us = 0; @@ -150,7 +150,7 @@ void CollationIteratorTest::TestPrevious(/* char* par */) if(U_FAILURE(status)){ errln("Couldn't create a collator"); } - iter = ((RuleBasedCollator*)c4)->createCollationElementIterator(source); + iter = (dynamic_cast(c4))->createCollationElementIterator(source); backAndForth(*iter); delete iter; delete c4; @@ -158,7 +158,7 @@ void CollationIteratorTest::TestPrevious(/* char* par */) source= CharsToUnicodeString("\\u0061\\u30CF\\u3099\\u30FC"); Collator *c5 = Collator::createInstance(Locale("ja", "JP", ""), status); - iter = ((RuleBasedCollator*)c5)->createCollationElementIterator(source); + iter = (dynamic_cast(c5))->createCollationElementIterator(source); if(U_FAILURE(status)){ errln("Couldn't create Japanese collator\n"); } @@ -332,7 +332,7 @@ void CollationIteratorTest::TestSetText(/* char* par */) || iter1->next(status) != (int32_t)CollationElementIterator::NULLORDER) { errln("Empty string should have no CEs."); } - ((StringCharacterIterator *)chariter)->setText(empty); + (dynamic_cast(chariter))->setText(empty); iter1->setText(*chariter, status); if (U_FAILURE(status) || iter1->next(status) != (int32_t)CollationElementIterator::NULLORDER) { @@ -459,7 +459,7 @@ void CollationIteratorTest::TestAssignment() { UErrorCode status = U_ZERO_ERROR; RuleBasedCollator *coll = - (RuleBasedCollator *)Collator::createInstance(status); + dynamic_cast(Collator::createInstance(status)); if (coll == nullptr || U_FAILURE(status)) { @@ -539,7 +539,7 @@ void CollationIteratorTest::TestConstructors() { UErrorCode status = U_ZERO_ERROR; RuleBasedCollator *coll = - (RuleBasedCollator *)Collator::createInstance(status); + dynamic_cast(Collator::createInstance(status)); if (coll == nullptr || U_FAILURE(status)) { errln("Couldn't create a default collator."); @@ -596,7 +596,7 @@ void CollationIteratorTest::TestStrengthOrder() UErrorCode status = U_ZERO_ERROR; RuleBasedCollator *coll = - (RuleBasedCollator *)Collator::createInstance(status); + dynamic_cast(Collator::createInstance(status)); if (coll == nullptr || U_FAILURE(status)) { errln("Couldn't create a default collator."); diff --git a/icu4c/source/test/intltest/loctest.cpp b/icu4c/source/test/intltest/loctest.cpp index 057d2984509..8c2c6470226 100644 --- a/icu4c/source/test/intltest/loctest.cpp +++ b/icu4c/source/test/intltest/loctest.cpp @@ -1192,8 +1192,8 @@ void LocaleTest::TestThaiCurrencyFormat() { UErrorCode status = U_ZERO_ERROR; - DecimalFormat *thaiCurrency = (DecimalFormat*)NumberFormat::createCurrencyInstance( - Locale("th", "TH"), status); + DecimalFormat *thaiCurrency = dynamic_cast(NumberFormat::createCurrencyInstance( + Locale("th", "TH"), status)); UnicodeString posPrefix(u"\u0E3F"); UnicodeString temp; diff --git a/icu4c/source/test/intltest/measfmttest.cpp b/icu4c/source/test/intltest/measfmttest.cpp index 0db117a4bbb..cffb546bc38 100644 --- a/icu4c/source/test/intltest/measfmttest.cpp +++ b/icu4c/source/test/intltest/measfmttest.cpp @@ -4315,7 +4315,7 @@ void MeasureFormatTest::Test10219FractionalPlurals() { for (int j = 0; j < UPRV_LENGTHOF(values); j++) { for (int i = 0; i < UPRV_LENGTHOF(expected[j]); i++) { DecimalFormat *df = - (DecimalFormat *) NumberFormat::createInstance(en, status); + dynamic_cast(NumberFormat::createInstance(en, status)); if (U_FAILURE(status)) { dataerrln("Error creating Number format - %s", u_errorName(status)); return; diff --git a/icu4c/source/test/intltest/mnkytst.cpp b/icu4c/source/test/intltest/mnkytst.cpp index b67eea910e8..ef926392c23 100644 --- a/icu4c/source/test/intltest/mnkytst.cpp +++ b/icu4c/source/test/intltest/mnkytst.cpp @@ -220,7 +220,7 @@ void CollationMonkeyTest::TestRules(/* char* par */){ logln("Demo Test 1 : Create a new table collation with rules \"& z < 0x00e4\""); UErrorCode status = U_ZERO_ERROR; Collator *col = Collator::createInstance("en_US", status); - const UnicodeString baseRules = ((RuleBasedCollator*)col)->getRules(); + const UnicodeString baseRules = (dynamic_cast(col))->getRules(); UnicodeString newRules(" & z < "); newRules.append((char16_t)0x00e4); newRules.insert(0, baseRules); diff --git a/icu4c/source/test/intltest/numfmtst.cpp b/icu4c/source/test/intltest/numfmtst.cpp index 8254b707343..f2c5d2b63cf 100644 --- a/icu4c/source/test/intltest/numfmtst.cpp +++ b/icu4c/source/test/intltest/numfmtst.cpp @@ -421,7 +421,7 @@ NumberFormatTest::TestPatterns(void) errln((UnicodeString)"FAIL: Pattern " + pat[i] + " should transmute to " + newpat[i] + "; " + newp + " seen instead"); - UnicodeString s; (*(NumberFormat*)&fmt).format((int32_t)0, s); + UnicodeString s; (*dynamic_cast(&fmt)).format((int32_t)0, s); if (!(s == num[i])) { errln((UnicodeString)"FAIL: Pattern " + pat[i] + " should format zero as " + num[i] + @@ -576,7 +576,7 @@ NumberFormatTest::TestExponential(void) int32_t v; for (v=0; v(&fmt)).format(val[v], s); logln((UnicodeString)" " + val[v] + " -format-> " + s); if (s != valFormat[v+ival]) errln((UnicodeString)"FAIL: Expected " + valFormat[v+ival]); @@ -625,7 +625,7 @@ NumberFormatTest::TestExponential(void) for (v=0; v(&fmt)).format(lval[v], s); logln((UnicodeString)" " + lval[v] + "L -format-> " + s); if (s != lvalFormat[v+ilval]) errln((UnicodeString)"ERROR: Expected " + lvalFormat[v+ilval] + " Got: " + s); @@ -660,7 +660,7 @@ void NumberFormatTest::TestScientific2() { // jb 2552 UErrorCode status = U_ZERO_ERROR; - DecimalFormat* fmt = (DecimalFormat*)NumberFormat::createCurrencyInstance("en_US", status); + DecimalFormat* fmt = dynamic_cast(NumberFormat::createCurrencyInstance("en_US", status)); if (U_SUCCESS(status)) { double num = 12.34; expect(*fmt, num, "$12.34"); @@ -809,7 +809,7 @@ NumberFormatTest::TestQuotes(void) pat = new UnicodeString("a'fo''o'b#"); DecimalFormat *fmt = new DecimalFormat(*pat, *sym, status); UnicodeString s; - ((NumberFormat*)fmt)->format((int32_t)123, s); + (dynamic_cast(fmt))->format((int32_t)123, s); logln((UnicodeString)"Pattern \"" + *pat + "\""); logln((UnicodeString)" Format 123 -> " + escape(s)); if (!(s=="afo'ob123")) @@ -821,7 +821,7 @@ NumberFormatTest::TestQuotes(void) pat = new UnicodeString("a''b#"); fmt = new DecimalFormat(*pat, *sym, status); - ((NumberFormat*)fmt)->format((int32_t)123, s); + (dynamic_cast(fmt))->format((int32_t)123, s); logln((UnicodeString)"Pattern \"" + *pat + "\""); logln((UnicodeString)" Format 123 -> " + escape(s)); if (!(s=="a'b123")) @@ -850,13 +850,13 @@ NumberFormatTest::TestCurrencySign(void) pat.append(currency).append("#,##0.00;-"). append(currency).append("#,##0.00"); DecimalFormat *fmt = new DecimalFormat(pat, *sym, status); - UnicodeString s; ((NumberFormat*)fmt)->format(1234.56, s); + UnicodeString s; (dynamic_cast(fmt))->format(1234.56, s); pat.truncate(0); logln((UnicodeString)"Pattern \"" + fmt->toPattern(pat) + "\""); logln((UnicodeString)" Format " + 1234.56 + " -> " + escape(s)); if (s != "$1,234.56") dataerrln((UnicodeString)"FAIL: Expected $1,234.56"); s.truncate(0); - ((NumberFormat*)fmt)->format(- 1234.56, s); + (dynamic_cast(fmt))->format(- 1234.56, s); logln((UnicodeString)" Format " + (-1234.56) + " -> " + escape(s)); if (s != "-$1,234.56") dataerrln((UnicodeString)"FAIL: Expected -$1,234.56"); delete fmt; @@ -868,12 +868,12 @@ NumberFormatTest::TestCurrencySign(void) append(" -#,##0.00"); fmt = new DecimalFormat(pat, *sym, status); s.truncate(0); - ((NumberFormat*)fmt)->format(1234.56, s); + (dynamic_cast(fmt))->format(1234.56, s); logln((UnicodeString)"Pattern \"" + fmt->toPattern(pat) + "\""); logln((UnicodeString)" Format " + 1234.56 + " -> " + escape(s)); if (s != "USD 1,234.56") dataerrln((UnicodeString)"FAIL: Expected USD 1,234.56"); s.truncate(0); - ((NumberFormat*)fmt)->format(-1234.56, s); + (dynamic_cast(fmt))->format(-1234.56, s); logln((UnicodeString)" Format " + (-1234.56) + " -> " + escape(s)); if (s != "USD -1,234.56") dataerrln((UnicodeString)"FAIL: Expected USD -1,234.56"); delete fmt; @@ -2872,7 +2872,7 @@ void NumberFormatTest::expect(NumberFormat& fmt, const UnicodeString& str, const return; } UnicodeString pat; - ((DecimalFormat*) &fmt)->toPattern(pat); + (dynamic_cast(&fmt))->toPattern(pat); if (equalValue(num, n)) { logln(UnicodeString("Ok \"") + str + "\" x " + pat + " = " + @@ -2945,7 +2945,7 @@ void NumberFormatTest::expect(NumberFormat& fmt, const Formattable& n, fmt.format(n, saw, pos, status); CHECK(status, "NumberFormat::format"); UnicodeString pat; - ((DecimalFormat*) &fmt)->toPattern(pat); + (dynamic_cast(&fmt))->toPattern(pat); if (saw == exp) { logln(UnicodeString("Ok ") + toString(n) + " x " + escape(pat) + " = \"" + @@ -2989,7 +2989,7 @@ void NumberFormatTest::expect(NumberFormat* fmt, const Formattable& n, void NumberFormatTest::expectCurrency(NumberFormat& nf, const Locale& locale, double value, const UnicodeString& string) { UErrorCode ec = U_ZERO_ERROR; - DecimalFormat& fmt = * (DecimalFormat*) &nf; + DecimalFormat& fmt = * dynamic_cast(&nf); const char16_t DEFAULT_CURR[] = {45/*-*/,0}; char16_t curr[4]; u_strcpy(curr, DEFAULT_CURR); @@ -3294,7 +3294,7 @@ void NumberFormatTest::TestCurrencyFormat() /* Port of ICU4J rounding test. */ void NumberFormatTest::TestRounding() { UErrorCode status = U_ZERO_ERROR; - DecimalFormat *df = (DecimalFormat*)NumberFormat::createCurrencyInstance(Locale::getEnglish(), status); + DecimalFormat *df = dynamic_cast(NumberFormat::createCurrencyInstance(Locale::getEnglish(), status)); if (U_FAILURE(status)) { dataerrln("Unable to create decimal formatter. - %s", u_errorName(status)); @@ -3332,7 +3332,7 @@ void NumberFormatTest::TestRoundingPattern() { int32_t numOfTests = UPRV_LENGTHOF(tests); UnicodeString result; - DecimalFormat *df = (DecimalFormat*)NumberFormat::createCurrencyInstance(Locale::getEnglish(), status); + DecimalFormat *df = dynamic_cast(NumberFormat::createCurrencyInstance(Locale::getEnglish(), status)); if (U_FAILURE(status)) { dataerrln("Unable to create decimal formatter. - %s", u_errorName(status)); return; @@ -3662,7 +3662,7 @@ NumberFormatTest::TestMultiCurrencySign() { continue; } UnicodeString s; - ((NumberFormat*) fmt)->format(numberToBeFormat, s); + (dynamic_cast(fmt))->format(numberToBeFormat, s); // DATA[i][3] is the currency format result using a // single currency sign. // DATA[i][4] is the currency format result using @@ -6706,7 +6706,7 @@ void NumberFormatTest::TestFieldPositionIterator() { FieldPositionIterator iter2; FieldPosition pos; - DecimalFormat *decFmt = (DecimalFormat *) NumberFormat::createInstance(status); + DecimalFormat *decFmt = dynamic_cast(NumberFormat::createInstance(status)); if (failure(status, "NumberFormat::createInstance", true)) return; double num = 1234.56; @@ -6736,7 +6736,7 @@ void NumberFormatTest::TestFieldPositionIterator() { void NumberFormatTest::TestFormatAttributes() { Locale locale("en_US"); UErrorCode status = U_ZERO_ERROR; - DecimalFormat *decFmt = (DecimalFormat *) NumberFormat::createInstance(locale, UNUM_CURRENCY, status); + DecimalFormat *decFmt = dynamic_cast(NumberFormat::createInstance(locale, UNUM_CURRENCY, status)); if (failure(status, "NumberFormat::createInstance", true)) return; double val = 12345.67; @@ -6769,7 +6769,7 @@ void NumberFormatTest::TestFormatAttributes() { } delete decFmt; - decFmt = (DecimalFormat *) NumberFormat::createInstance(locale, UNUM_SCIENTIFIC, status); + decFmt = dynamic_cast(NumberFormat::createInstance(locale, UNUM_SCIENTIFIC, status)); val = -0.0000123; { int32_t expected[] = { @@ -7555,7 +7555,7 @@ void NumberFormatTest::TestSignificantDigits(void) { UErrorCode status = U_ZERO_ERROR; Locale locale("en_US"); - LocalPointer numberFormat(static_cast( + LocalPointer numberFormat(dynamic_cast( NumberFormat::createInstance(locale, status))); CHECK_DATA(status,"NumberFormat::createInstance"); @@ -7608,7 +7608,7 @@ void NumberFormatTest::TestSignificantDigits(void) { void NumberFormatTest::TestShowZero() { UErrorCode status = U_ZERO_ERROR; Locale locale("en_US"); - LocalPointer numberFormat(static_cast( + LocalPointer numberFormat(dynamic_cast( NumberFormat::createInstance(locale, status))); CHECK_DATA(status, "NumberFormat::createInstance"); @@ -7625,7 +7625,7 @@ void NumberFormatTest::TestShowZero() { void NumberFormatTest::TestBug9936() { UErrorCode status = U_ZERO_ERROR; Locale locale("en_US"); - LocalPointer numberFormat(static_cast( + LocalPointer numberFormat(dynamic_cast( NumberFormat::createInstance(locale, status))); if (U_FAILURE(status)) { dataerrln("File %s, Line %d: status = %s.\n", __FILE__, __LINE__, u_errorName(status)); @@ -7660,7 +7660,7 @@ void NumberFormatTest::TestBug9936() { void NumberFormatTest::TestParseNegativeWithFaLocale() { UErrorCode status = U_ZERO_ERROR; - DecimalFormat *test = (DecimalFormat *) NumberFormat::createInstance("fa", status); + DecimalFormat *test = dynamic_cast(NumberFormat::createInstance("fa", status)); CHECK_DATA(status, "NumberFormat::createInstance"); test->setLenient(true); Formattable af; @@ -7676,7 +7676,7 @@ void NumberFormatTest::TestParseNegativeWithFaLocale() { void NumberFormatTest::TestParseNegativeWithAlternateMinusSign() { UErrorCode status = U_ZERO_ERROR; - DecimalFormat *test = (DecimalFormat *) NumberFormat::createInstance("en", status); + DecimalFormat *test = dynamic_cast( NumberFormat::createInstance("en", status)); CHECK_DATA(status, "NumberFormat::createInstance"); test->setLenient(true); Formattable af; @@ -7841,7 +7841,7 @@ void NumberFormatTest::Test10419RoundingWith0FractionDigits() { { DecimalFormat::kRoundUp, 1.5, "2"}, }; UErrorCode status = U_ZERO_ERROR; - LocalPointer decfmt((DecimalFormat *) NumberFormat::createInstance(Locale("en_US"), status)); + LocalPointer decfmt(dynamic_cast( NumberFormat::createInstance(Locale("en_US"), status))); if (U_FAILURE(status)) { dataerrln("Failure creating DecimalFormat %s", u_errorName(status)); return; @@ -8185,7 +8185,7 @@ void NumberFormatTest::TestCurrencyUsage() { for(int i=0; i<2; i++){ status = U_ZERO_ERROR; if(i == 0){ - fmt = (DecimalFormat *) NumberFormat::createInstance(enUS_ISK, UNUM_CURRENCY, status); + fmt = dynamic_cast( NumberFormat::createInstance(enUS_ISK, UNUM_CURRENCY, status)); if (assertSuccess("en_US@currency=ISK/CURRENCY", status, true) == false) { continue; } @@ -8200,7 +8200,7 @@ void NumberFormatTest::TestCurrencyUsage() { fmt->setCurrencyUsage(UCURR_USAGE_CASH, &status); }else{ - fmt = (DecimalFormat *) NumberFormat::createInstance(enUS_ISK, UNUM_CASH_CURRENCY, status); + fmt = dynamic_cast( NumberFormat::createInstance(enUS_ISK, UNUM_CASH_CURRENCY, status)); if (assertSuccess("en_US@currency=ISK/CASH", status, true) == false) { continue; } @@ -8222,7 +8222,7 @@ void NumberFormatTest::TestCurrencyUsage() { for(int i=0; i<2; i++){ status = U_ZERO_ERROR; if(i == 0){ - fmt = (DecimalFormat *) NumberFormat::createInstance(enUS_CAD, UNUM_CURRENCY, status); + fmt = dynamic_cast( NumberFormat::createInstance(enUS_CAD, UNUM_CURRENCY, status)); if (assertSuccess("en_US@currency=CAD/CURRENCY", status, true) == false) { continue; } @@ -8232,7 +8232,7 @@ void NumberFormatTest::TestCurrencyUsage() { assertEquals("Test Currency Usage 3", u"CA$123.57", original_rounding); fmt->setCurrencyUsage(UCURR_USAGE_CASH, &status); }else{ - fmt = (DecimalFormat *) NumberFormat::createInstance(enUS_CAD, UNUM_CASH_CURRENCY, status); + fmt = dynamic_cast( NumberFormat::createInstance(enUS_CAD, UNUM_CASH_CURRENCY, status)); if (assertSuccess("en_US@currency=CAD/CASH", status, true) == false) { continue; } @@ -8250,13 +8250,13 @@ void NumberFormatTest::TestCurrencyUsage() { for(int i=0; i<2; i++){ status = U_ZERO_ERROR; if(i == 0){ - fmt = (DecimalFormat *) NumberFormat::createInstance(enUS_CAD, UNUM_CURRENCY, status); + fmt = dynamic_cast( NumberFormat::createInstance(enUS_CAD, UNUM_CURRENCY, status)); if (assertSuccess("en_US@currency=CAD/CURRENCY", status, true) == false) { continue; } fmt->setCurrencyUsage(UCURR_USAGE_CASH, &status); }else{ - fmt = (DecimalFormat *) NumberFormat::createInstance(enUS_CAD, UNUM_CASH_CURRENCY, status); + fmt = dynamic_cast( NumberFormat::createInstance(enUS_CAD, UNUM_CASH_CURRENCY, status)); if (assertSuccess("en_US@currency=CAD/CASH", status, true) == false) { continue; } @@ -8562,7 +8562,7 @@ void NumberFormatTest::Test11739_ParseLongCurrency() { IcuTestErrorCode status(*this, "Test11739_ParseLongCurrency"); LocalPointer nf(NumberFormat::createCurrencyInstance("sr_BA", status)); if (status.errDataIfFailureAndReset()) { return; } - ((DecimalFormat*) nf.getAlias())->applyPattern(u"#,##0.0 ยคยคยค", status); + (dynamic_cast(nf.getAlias()))->applyPattern(u"#,##0.0 ยคยคยค", status); ParsePosition ppos(0); LocalPointer result(nf->parseCurrency(u"1.500 ะฐะผะตั€ะธั‡ะบะธ ะดะพะปะฐั€", ppos)); assertEquals("Should parse to 1500 USD", -1, ppos.getErrorIndex()); @@ -8609,7 +8609,7 @@ void NumberFormatTest::Test11376_getAndSetPositivePrefix() { if (!assertSuccess("", status)) { return; } - DecimalFormat *dfmt = (DecimalFormat *) fmt.getAlias(); + DecimalFormat *dfmt = dynamic_cast( fmt.getAlias()); dfmt->setCurrency(USD); UnicodeString result; @@ -8629,7 +8629,7 @@ void NumberFormatTest::Test11376_getAndSetPositivePrefix() { if (!assertSuccess("", status)) { return; } - DecimalFormat *dfmt = (DecimalFormat *) fmt.getAlias(); + DecimalFormat *dfmt = dynamic_cast( fmt.getAlias()); UnicodeString result; assertEquals("", u" (unknown currency)", dfmt->getPositiveSuffix(result)); dfmt->setCurrency(USD); @@ -8791,7 +8791,7 @@ void NumberFormatTest::Test13391_chakmaParsing() { const char16_t* expectedScientific = u"\U00011137.\U00011139E\U00011138"; UnicodeString actualScientific; - df.adoptInstead(static_cast( + df.adoptInstead(dynamic_cast( NumberFormat::createScientificInstance(Locale("ccp"), status))); df->format(130, actualScientific, status); assertSuccess("Should not fail when formatting scientific in ccp", status); @@ -8882,8 +8882,8 @@ void NumberFormatTest::Test11318_DoubleConversion() { void NumberFormatTest::TestParsePercentRegression() { IcuTestErrorCode status(*this, "TestParsePercentRegression"); - LocalPointer df1((DecimalFormat*) NumberFormat::createInstance("en", status), status); - LocalPointer df2((DecimalFormat*) NumberFormat::createPercentInstance("en", status), status); + LocalPointer df1(dynamic_cast( NumberFormat::createInstance("en", status)), status); + LocalPointer df2(dynamic_cast( NumberFormat::createPercentInstance("en", status)), status); if (status.isFailure()) {return; } df1->setLenient(true); df2->setLenient(true); @@ -9229,7 +9229,7 @@ void NumberFormatTest::Test10354() { void NumberFormatTest::Test11645_ApplyPatternEquality() { IcuTestErrorCode status(*this, "Test11645_ApplyPatternEquality"); const char16_t* pattern = u"#,##0.0#"; - LocalPointer fmt((DecimalFormat*) NumberFormat::createInstance(status), status); + LocalPointer fmt(dynamic_cast(NumberFormat::createInstance(status)), status); if (!assertSuccess("", status, true, __FILE__, __LINE__)) { return; } fmt->applyPattern(pattern, status); LocalPointer fmtCopy; @@ -9274,10 +9274,10 @@ void NumberFormatTest::Test11645_ApplyPatternEquality() { void NumberFormatTest::Test12567() { IcuTestErrorCode errorCode(*this, "Test12567"); // Ticket #12567: DecimalFormat.equals() may not be symmetric - LocalPointer df1((DecimalFormat *) - NumberFormat::createInstance(Locale::getUS(), UNUM_CURRENCY, errorCode)); - LocalPointer df2((DecimalFormat *) - NumberFormat::createInstance(Locale::getUS(), UNUM_DECIMAL, errorCode)); + LocalPointer df1(dynamic_cast( + NumberFormat::createInstance(Locale::getUS(), UNUM_CURRENCY, errorCode))); + LocalPointer df2(dynamic_cast( + NumberFormat::createInstance(Locale::getUS(), UNUM_DECIMAL, errorCode))); if (!assertSuccess("", errorCode, true, __FILE__, __LINE__)) { return; } // NOTE: CurrencyPluralInfo equality not tested in C++ because its operator== is not defined. df1->applyPattern(u"0.00", errorCode); @@ -9399,7 +9399,7 @@ void NumberFormatTest::Test11649_DecFmtCurrencies() { void NumberFormatTest::Test13148_ParseGroupingSeparators() { IcuTestErrorCode status(*this, "Test13148"); LocalPointer fmt( - (DecimalFormat*)NumberFormat::createInstance("en-ZA", status), status); + dynamic_cast(NumberFormat::createInstance("en-ZA", status)), status); if (!assertSuccess("", status, true, __FILE__, __LINE__)) { return; } DecimalFormatSymbols symbols = *fmt->getDecimalFormatSymbols(); @@ -9707,7 +9707,7 @@ void NumberFormatTest::Test13850_EmptyStringCurrency() { void NumberFormatTest::Test20348_CurrencyPrefixOverride() { IcuTestErrorCode status(*this, "Test20348_CurrencyPrefixOverride"); - LocalPointer fmt(static_cast( + LocalPointer fmt(dynamic_cast( NumberFormat::createCurrencyInstance("en", status))); if (status.errIfFailureAndReset()) { return; } UnicodeString result; @@ -9743,7 +9743,7 @@ void NumberFormatTest::Test20348_CurrencyPrefixOverride() { void NumberFormatTest::Test20956_MonetarySymbolGetters() { IcuTestErrorCode status(*this, "Test20956_MonetarySymbolGetters"); - LocalPointer decimalFormat(static_cast( + LocalPointer decimalFormat(dynamic_cast( NumberFormat::createCurrencyInstance("et", status))); if (status.errDataIfFailureAndReset()) { return; @@ -9775,7 +9775,7 @@ void NumberFormatTest::Test20956_MonetarySymbolGetters() { void NumberFormatTest::Test20358_GroupingInPattern() { IcuTestErrorCode status(*this, "Test20358_GroupingInPattern"); - LocalPointer fmt(static_cast( + LocalPointer fmt(dynamic_cast( NumberFormat::createInstance("en", status))); if (status.errIfFailureAndReset()) { return; } UnicodeString result; @@ -9890,7 +9890,7 @@ void NumberFormatTest::Test13734_StrictFlexibleWhitespace() { void NumberFormatTest::Test20961_CurrencyPluralPattern() { IcuTestErrorCode status(*this, "Test20961_CurrencyPluralPattern"); { - LocalPointer decimalFormat(static_cast( + LocalPointer decimalFormat(dynamic_cast( NumberFormat::createInstance("en-US", UNUM_CURRENCY_PLURAL, status))); if (status.errDataIfFailureAndReset()) { return; @@ -9934,7 +9934,7 @@ void NumberFormatTest::Test21134_ToNumberFormatter() { } { // Case 3: currency plural info (different code path) - LocalPointer inner(static_cast( + LocalPointer inner(dynamic_cast( DecimalFormat::createInstance("en-US", UNUM_CURRENCY_PLURAL, status))); if (auto ptr = inner->toNumberFormatter(status)) { // Copy constructor @@ -10133,7 +10133,7 @@ void NumberFormatTest::Test21556_CurrencyAsDecimal() { { LocalPointer nf(NumberFormat::createCurrencyInstance("en-GB", status)); - DecimalFormat* df = static_cast(nf.getAlias()); + DecimalFormat* df = dynamic_cast(nf.getAlias()); df->applyPattern(u"a0ยค00b", status); UnicodeString result; FieldPosition fp(UNUM_CURRENCY_FIELD); diff --git a/icu4c/source/test/intltest/numrgts.cpp b/icu4c/source/test/intltest/numrgts.cpp index a9c71cf0120..62570fe41d8 100644 --- a/icu4c/source/test/intltest/numrgts.cpp +++ b/icu4c/source/test/intltest/numrgts.cpp @@ -1947,7 +1947,7 @@ void NumberFormatRegressionTest::Test4145457() { return; } - DecimalFormatSymbols *sym = (DecimalFormatSymbols*) nf->getDecimalFormatSymbols(); + DecimalFormatSymbols *sym = const_cast(nf->getDecimalFormatSymbols()); sym->setSymbol(DecimalFormatSymbols::kDecimalSeparatorSymbol, (char16_t)/*'\''*/0x0027); nf->setDecimalFormatSymbols(*sym); double pi = 3.14159; @@ -2443,7 +2443,7 @@ void NumberFormatRegressionTest::Test4212072(void) { if (U_FAILURE(status)) { continue; } - DecimalFormat *df = (DecimalFormat*) nf; + DecimalFormat *df = dynamic_cast(nf); // Test toPattern/applyPattern round trip UnicodeString pat; @@ -2509,7 +2509,7 @@ void NumberFormatRegressionTest::Test4212072(void) { */ void NumberFormatRegressionTest::Test4216742(void) { UErrorCode status = U_ZERO_ERROR; - DecimalFormat *fmt = (DecimalFormat*) NumberFormat::createInstance(Locale::getUS(), status); + DecimalFormat *fmt = dynamic_cast(NumberFormat::createInstance(Locale::getUS(), status)); if (failure(status, "createInstance", Locale::getUS(), true)){ delete fmt; return; @@ -2584,7 +2584,7 @@ void NumberFormatRegressionTest::Test4161100(void) { nf->format(a, s); UnicodeString pat; logln(UnicodeString() + a + " x " + - ((DecimalFormat*) nf)->toPattern(pat) + " = " + s); + (dynamic_cast(nf))->toPattern(pat) + " = " + s); if (s != UnicodeString("-0.1")) { errln("FAIL"); } diff --git a/icu4c/source/test/intltest/plurfmts.cpp b/icu4c/source/test/intltest/plurfmts.cpp index 32b3ff16619..3020be93c82 100644 --- a/icu4c/source/test/intltest/plurfmts.cpp +++ b/icu4c/source/test/intltest/plurfmts.cpp @@ -240,8 +240,8 @@ void PluralFormatTest::pluralFormatUnitTest(/*char *par*/) errln("ERROR: PluralFormat failed to apply pattern- "+patternTestData[i]); continue; } - numberFormatTest(&plFmt, numFmt.getAlias(), 1, 10, (UnicodeString *)&patternOddTestResult[i], - (UnicodeString *)&patternEvenTestResult[i], overwrite[i], &message); + numberFormatTest(&plFmt, numFmt.getAlias(), 1, 10, dynamic_cast(&patternOddTestResult[i]), + dynamic_cast(&patternEvenTestResult[i]), overwrite[i], &message); } // ======= Test set locale diff --git a/icu4c/source/test/intltest/rbbiapts.cpp b/icu4c/source/test/intltest/rbbiapts.cpp index 5a1ed42be13..fd86b299364 100644 --- a/icu4c/source/test/intltest/rbbiapts.cpp +++ b/icu4c/source/test/intltest/rbbiapts.cpp @@ -50,10 +50,10 @@ void RBBIAPITest::TestCloneEquals() { UErrorCode status=U_ZERO_ERROR; - RuleBasedBreakIterator* bi1 = (RuleBasedBreakIterator*)RuleBasedBreakIterator::createCharacterInstance(Locale::getDefault(), status); - RuleBasedBreakIterator* biequal = (RuleBasedBreakIterator*)RuleBasedBreakIterator::createCharacterInstance(Locale::getDefault(), status); - RuleBasedBreakIterator* bi3 = (RuleBasedBreakIterator*)RuleBasedBreakIterator::createCharacterInstance(Locale::getDefault(), status); - RuleBasedBreakIterator* bi2 = (RuleBasedBreakIterator*)RuleBasedBreakIterator::createWordInstance(Locale::getDefault(), status); + RuleBasedBreakIterator* bi1 = dynamic_cast(RuleBasedBreakIterator::createCharacterInstance(Locale::getDefault(), status)); + RuleBasedBreakIterator* biequal = dynamic_cast(RuleBasedBreakIterator::createCharacterInstance(Locale::getDefault(), status)); + RuleBasedBreakIterator* bi3 = dynamic_cast(RuleBasedBreakIterator::createCharacterInstance(Locale::getDefault(), status)); + RuleBasedBreakIterator* bi2 = dynamic_cast(RuleBasedBreakIterator::createWordInstance(Locale::getDefault(), status)); if(U_FAILURE(status)){ errcheckln(status, "Fail : in construction - %s", u_errorName(status)); return; @@ -88,7 +88,7 @@ void RBBIAPITest::TestCloneEquals() // source and dest iterator produce the same next() after assignment. // deleting one doesn't disable the other. logln("Testing assignment"); - RuleBasedBreakIterator *bix = (RuleBasedBreakIterator *)BreakIterator::createLineInstance(Locale::getDefault(), status); + RuleBasedBreakIterator *bix = dynamic_cast(BreakIterator::createLineInstance(Locale::getDefault(), status)); if(U_FAILURE(status)){ errcheckln(status, "Fail : in construction - %s", u_errorName(status)); return; @@ -190,9 +190,9 @@ void RBBIAPITest::TestgetRules() UErrorCode status=U_ZERO_ERROR; LocalPointer bi1( - (RuleBasedBreakIterator*)RuleBasedBreakIterator::createCharacterInstance(Locale::getDefault(), status), status); + dynamic_cast(RuleBasedBreakIterator::createCharacterInstance(Locale::getDefault(), status)), status); LocalPointer bi2( - (RuleBasedBreakIterator*)RuleBasedBreakIterator::createWordInstance(Locale::getDefault(), status), status); + dynamic_cast(RuleBasedBreakIterator::createWordInstance(Locale::getDefault(), status)), status); if(U_FAILURE(status)){ errcheckln(status, "%s:%d, FAIL: in construction - %s", __FILE__, __LINE__, u_errorName(status)); return; @@ -220,9 +220,9 @@ void RBBIAPITest::TestgetRules() void RBBIAPITest::TestHashCode() { UErrorCode status=U_ZERO_ERROR; - RuleBasedBreakIterator* bi1 = (RuleBasedBreakIterator*)RuleBasedBreakIterator::createCharacterInstance(Locale::getDefault(), status); - RuleBasedBreakIterator* bi3 = (RuleBasedBreakIterator*)RuleBasedBreakIterator::createCharacterInstance(Locale::getDefault(), status); - RuleBasedBreakIterator* bi2 = (RuleBasedBreakIterator*)RuleBasedBreakIterator::createWordInstance(Locale::getDefault(), status); + RuleBasedBreakIterator* bi1 = dynamic_cast(RuleBasedBreakIterator::createCharacterInstance(Locale::getDefault(), status)); + RuleBasedBreakIterator* bi3 = dynamic_cast(RuleBasedBreakIterator::createCharacterInstance(Locale::getDefault(), status)); + RuleBasedBreakIterator* bi2 = dynamic_cast(RuleBasedBreakIterator::createWordInstance(Locale::getDefault(), status)); if(U_FAILURE(status)){ errcheckln(status, "Fail : in construction - %s", u_errorName(status)); delete bi1; @@ -262,8 +262,8 @@ void RBBIAPITest::TestGetSetAdoptText() IcuTestErrorCode status(*this, "TestGetSetAdoptText"); UnicodeString str1="first string."; UnicodeString str2="Second string."; - LocalPointer charIter1((RuleBasedBreakIterator*)RuleBasedBreakIterator::createCharacterInstance(Locale::getDefault(), status)); - LocalPointer wordIter1((RuleBasedBreakIterator*)RuleBasedBreakIterator::createWordInstance(Locale::getDefault(), status)); + LocalPointer charIter1(dynamic_cast(RuleBasedBreakIterator::createCharacterInstance(Locale::getDefault(), status))); + LocalPointer wordIter1(dynamic_cast(RuleBasedBreakIterator::createWordInstance(Locale::getDefault(), status))); if(status.isFailure()){ errcheckln(status, "Fail : in construction - %s", status.errorName()); return; @@ -385,42 +385,42 @@ void RBBIAPITest::TestIteration() // Testing for correct operation of the break rules happens elsewhere. UErrorCode status=U_ZERO_ERROR; - RuleBasedBreakIterator* bi = (RuleBasedBreakIterator*)RuleBasedBreakIterator::createCharacterInstance(Locale::getDefault(), status); + RuleBasedBreakIterator* bi = dynamic_cast(RuleBasedBreakIterator::createCharacterInstance(Locale::getDefault(), status)); if (U_FAILURE(status) || bi == nullptr) { errcheckln(status, "Failure creating character break iterator. Status = %s", u_errorName(status)); } delete bi; status=U_ZERO_ERROR; - bi = (RuleBasedBreakIterator*)RuleBasedBreakIterator::createWordInstance(Locale::getDefault(), status); + bi = dynamic_cast(RuleBasedBreakIterator::createWordInstance(Locale::getDefault(), status)); if (U_FAILURE(status) || bi == nullptr) { errcheckln(status, "Failure creating Word break iterator. Status = %s", u_errorName(status)); } delete bi; status=U_ZERO_ERROR; - bi = (RuleBasedBreakIterator*)RuleBasedBreakIterator::createLineInstance(Locale::getDefault(), status); + bi = dynamic_cast(RuleBasedBreakIterator::createLineInstance(Locale::getDefault(), status)); if (U_FAILURE(status) || bi == nullptr) { errcheckln(status, "Failure creating Line break iterator. Status = %s", u_errorName(status)); } delete bi; status=U_ZERO_ERROR; - bi = (RuleBasedBreakIterator*)RuleBasedBreakIterator::createSentenceInstance(Locale::getDefault(), status); + bi = dynamic_cast(RuleBasedBreakIterator::createSentenceInstance(Locale::getDefault(), status)); if (U_FAILURE(status) || bi == nullptr) { errcheckln(status, "Failure creating Sentence break iterator. Status = %s", u_errorName(status)); } delete bi; status=U_ZERO_ERROR; - bi = (RuleBasedBreakIterator*)RuleBasedBreakIterator::createTitleInstance(Locale::getDefault(), status); + bi = dynamic_cast(RuleBasedBreakIterator::createTitleInstance(Locale::getDefault(), status)); if (U_FAILURE(status) || bi == nullptr) { errcheckln(status, "Failure creating Title break iterator. Status = %s", u_errorName(status)); } delete bi; status=U_ZERO_ERROR; - bi = (RuleBasedBreakIterator*)RuleBasedBreakIterator::createCharacterInstance(Locale::getDefault(), status); + bi = dynamic_cast(RuleBasedBreakIterator::createCharacterInstance(Locale::getDefault(), status)); if (U_FAILURE(status) || bi == nullptr) { errcheckln(status, "Failure creating character break iterator. Status = %s", u_errorName(status)); return; // Skip the rest of these tests. @@ -1130,7 +1130,7 @@ void RBBIAPITest::TestRefreshInputText() { UErrorCode status = U_ZERO_ERROR; UText ut1 = UTEXT_INITIALIZER; UText ut2 = UTEXT_INITIALIZER; - RuleBasedBreakIterator *bi = (RuleBasedBreakIterator *)BreakIterator::createLineInstance(Locale::getEnglish(), status); + RuleBasedBreakIterator *bi = dynamic_cast(BreakIterator::createLineInstance(Locale::getEnglish(), status)); TEST_ASSERT_SUCCESS(status); utext_openUChars(&ut1, testStr, -1, &status); diff --git a/icu4c/source/test/intltest/rbbitst.cpp b/icu4c/source/test/intltest/rbbitst.cpp index 264b418421a..136930f3f34 100644 --- a/icu4c/source/test/intltest/rbbitst.cpp +++ b/icu4c/source/test/intltest/rbbitst.cpp @@ -1206,28 +1206,28 @@ void RBBITest::TestUnicodeFiles() { RuleBasedBreakIterator *bi; UErrorCode status = U_ZERO_ERROR; - bi = (RuleBasedBreakIterator *)BreakIterator::createCharacterInstance(Locale::getEnglish(), status); + bi = dynamic_cast(BreakIterator::createCharacterInstance(Locale::getEnglish(), status)); TEST_ASSERT_SUCCESS(status); if (U_SUCCESS(status)) { runUnicodeTestData("GraphemeBreakTest.txt", bi); } delete bi; - bi = (RuleBasedBreakIterator *)BreakIterator::createWordInstance(Locale::getEnglish(), status); + bi = dynamic_cast(BreakIterator::createWordInstance(Locale::getEnglish(), status)); TEST_ASSERT_SUCCESS(status); if (U_SUCCESS(status)) { runUnicodeTestData("WordBreakTest.txt", bi); } delete bi; - bi = (RuleBasedBreakIterator *)BreakIterator::createSentenceInstance(Locale::getEnglish(), status); + bi = dynamic_cast(BreakIterator::createSentenceInstance(Locale::getEnglish(), status)); TEST_ASSERT_SUCCESS(status); if (U_SUCCESS(status)) { runUnicodeTestData("SentenceBreakTest.txt", bi); } delete bi; - bi = (RuleBasedBreakIterator *)BreakIterator::createLineInstance(Locale::getEnglish(), status); + bi = dynamic_cast(BreakIterator::createLineInstance(Locale::getEnglish(), status)); TEST_ASSERT_SUCCESS(status); if (U_SUCCESS(status)) { runUnicodeTestData("LineBreakTest.txt", bi); @@ -1562,7 +1562,7 @@ std::string RBBIMonkeyKind::getAppliedRule(int32_t position){ std::string RBBIMonkeyKind::classNameFromCodepoint(const UChar32 c) { // Simply iterate through charClasses to find character's class for (int aClassNum = 0; aClassNum < charClasses()->size(); aClassNum++) { - UnicodeSet *classSet = (UnicodeSet *)charClasses()->elementAt(aClassNum); + UnicodeSet *classSet = static_cast(charClasses()->elementAt(aClassNum)); if (classSet->contains(c)) { return classNames[aClassNum]; } @@ -3993,7 +3993,7 @@ void RBBITest::RunMonkey(BreakIterator *bi, RBBIMonkeyKind &mk, const char *name // Verify that the character classes all have at least one member. for (i=0; ielementAt(i); + UnicodeSet *s = static_cast(chClasses->elementAt(i)); if (s == nullptr || s->size() == 0) { errln("Character Class #%d is null or of zero size.", i); return; @@ -4316,10 +4316,10 @@ void RBBITest::TestBug9983(void) { "\\u0000").unescape(); UErrorCode status = U_ZERO_ERROR; - LocalPointer brkiter(static_cast( + LocalPointer brkiter(dynamic_cast( BreakIterator::createWordInstance(Locale::getRoot(), status))); TEST_ASSERT_SUCCESS(status); - LocalPointer brkiterPOSIX(static_cast( + LocalPointer brkiterPOSIX(dynamic_cast( BreakIterator::createWordInstance(Locale::createFromName("en_US_POSIX"), status))); TEST_ASSERT_SUCCESS(status); if (U_FAILURE(status)) { @@ -4521,8 +4521,8 @@ void RBBITest::TestEmoji() { void RBBITest::TestBug12519() { UErrorCode status = U_ZERO_ERROR; - LocalPointer biEn((RuleBasedBreakIterator *)BreakIterator::createWordInstance(Locale::getEnglish(), status)); - LocalPointer biFr((RuleBasedBreakIterator *)BreakIterator::createWordInstance(Locale::getFrance(), status)); + LocalPointer biEn(dynamic_cast(BreakIterator::createWordInstance(Locale::getEnglish(), status))); + LocalPointer biFr(dynamic_cast(BreakIterator::createWordInstance(Locale::getFrance(), status))); if (!assertSuccess(WHERE, status)) { dataerrln("%s %d status = %s", __FILE__, __LINE__, u_errorName(status)); return; @@ -4540,7 +4540,7 @@ void RBBITest::TestBug12519() { assertTrue(WHERE, *biFr == *cloneFr); assertTrue(WHERE, Locale::getFrench() == cloneFr->getLocale(ULOC_VALID_LOCALE, status)); - LocalPointerbiDe((RuleBasedBreakIterator *)BreakIterator::createLineInstance(Locale::getGerman(), status)); + LocalPointerbiDe(dynamic_cast(BreakIterator::createLineInstance(Locale::getGerman(), status))); UnicodeString text("Hallo Welt"); biDe->setText(text); assertTrue(WHERE "before assignment of \"biDe = biFr\", they should be different, but are equal.", *biFr != *biDe); @@ -4570,7 +4570,7 @@ void RBBITest::TestTableRedundancies() { UErrorCode status = U_ZERO_ERROR; LocalPointer bi ( - (RuleBasedBreakIterator *)BreakIterator::createLineInstance(Locale::getEnglish(), status)); + dynamic_cast(BreakIterator::createLineInstance(Locale::getEnglish(), status))); assertSuccess(WHERE, status); if (U_FAILURE(status)) return; @@ -4586,7 +4586,7 @@ void RBBITest::TestTableRedundancies() { for (int32_t column = 0; column < numCharClasses; column++) { UnicodeString s; for (int32_t r = 1; r < (int32_t)fwtbl->fNumStates; r++) { - RBBIStateTableRow *row = (RBBIStateTableRow *) (fwtbl->fTableData + (fwtbl->fRowLen * r)); + RBBIStateTableRow *row = reinterpret_cast(const_cast(fwtbl->fTableData + (fwtbl->fRowLen * r))); s.append(in8Bits ? row->r8.fNextState[column] : row->r16.fNextState[column]); } columns.push_back(s); @@ -4607,7 +4607,7 @@ void RBBITest::TestTableRedundancies() { std::vector rows; for (int32_t r=0; r < (int32_t)fwtbl->fNumStates; r++) { UnicodeString s; - RBBIStateTableRow *row = (RBBIStateTableRow *) (fwtbl->fTableData + (fwtbl->fRowLen * r)); + RBBIStateTableRow *row = reinterpret_cast(const_cast((fwtbl->fTableData + (fwtbl->fRowLen * r)))); if (in8Bits) { s.append(row->r8.fAccepting); s.append(row->r8.fLookAhead); @@ -4641,7 +4641,7 @@ void RBBITest::TestTableRedundancies() { void RBBITest::TestBug13447() { UErrorCode status = U_ZERO_ERROR; LocalPointer bi( - (RuleBasedBreakIterator *)BreakIterator::createWordInstance(Locale::getEnglish(), status)); + dynamic_cast(BreakIterator::createWordInstance(Locale::getEnglish(), status))); assertSuccess(WHERE, status); if (U_FAILURE(status)) return; UnicodeString data(u"1234"); @@ -4665,20 +4665,20 @@ void RBBITest::TestBug13447() { void RBBITest::TestReverse() { UErrorCode status = U_ZERO_ERROR; - TestReverse(std::unique_ptr((RuleBasedBreakIterator *) - BreakIterator::createCharacterInstance(Locale::getEnglish(), status))); + TestReverse(std::unique_ptr(dynamic_cast( + BreakIterator::createCharacterInstance(Locale::getEnglish(), status)))); assertSuccess(WHERE, status, true); status = U_ZERO_ERROR; - TestReverse(std::unique_ptr((RuleBasedBreakIterator *) - BreakIterator::createWordInstance(Locale::getEnglish(), status))); + TestReverse(std::unique_ptr(dynamic_cast( + BreakIterator::createWordInstance(Locale::getEnglish(), status)))); assertSuccess(WHERE, status, true); status = U_ZERO_ERROR; - TestReverse(std::unique_ptr((RuleBasedBreakIterator *) - BreakIterator::createLineInstance(Locale::getEnglish(), status))); + TestReverse(std::unique_ptr(dynamic_cast( + BreakIterator::createLineInstance(Locale::getEnglish(), status)))); assertSuccess(WHERE, status, true); status = U_ZERO_ERROR; - TestReverse(std::unique_ptr((RuleBasedBreakIterator *) - BreakIterator::createSentenceInstance(Locale::getEnglish(), status))); + TestReverse(std::unique_ptr(dynamic_cast( + BreakIterator::createSentenceInstance(Locale::getEnglish(), status)))); assertSuccess(WHERE, status, true); } @@ -4743,8 +4743,8 @@ void RBBITest::TestReverse(std::unique_ptrbi) { void RBBITest::TestBug13692() { UErrorCode status = U_ZERO_ERROR; - LocalPointer bi ((RuleBasedBreakIterator *) - BreakIterator::createWordInstance(Locale::getEnglish(), status), status); + LocalPointer bi (dynamic_cast( + BreakIterator::createWordInstance(Locale::getEnglish(), status)), status); if (!assertSuccess(WHERE, status, true)) { return; } @@ -4778,8 +4778,8 @@ void RBBITest::TestProperties() { // void RBBITest::TestDebug(void) { UErrorCode status = U_ZERO_ERROR; - LocalPointer bi ((RuleBasedBreakIterator *) - BreakIterator::createCharacterInstance(Locale::getEnglish(), status), status); + LocalPointer bi (dynamic_cast( + BreakIterator::createCharacterInstance(Locale::getEnglish(), status)), status); if (!assertSuccess(WHERE, status, true)) { return; } @@ -5495,7 +5495,7 @@ void RBBITest::TestRandomAccess() { UErrorCode status = U_ZERO_ERROR; LocalPointer bi( - (RuleBasedBreakIterator *)BreakIterator::createLineInstance(Locale::getEnglish(), status), + dynamic_cast(BreakIterator::createLineInstance(Locale::getEnglish(), status)), status); if (!assertSuccess(WHERE, status)) { return; }; diff --git a/icu4c/source/test/intltest/regcoll.cpp b/icu4c/source/test/intltest/regcoll.cpp index 743a815e644..5717f5bcf39 100644 --- a/icu4c/source/test/intltest/regcoll.cpp +++ b/icu4c/source/test/intltest/regcoll.cpp @@ -24,7 +24,7 @@ CollationRegressionTest::CollationRegressionTest() { UErrorCode status = U_ZERO_ERROR; - en_us = (RuleBasedCollator *)Collator::createInstance(Locale::getUS(), status); + en_us = dynamic_cast(Collator::createInstance(Locale::getUS(), status)); if(U_FAILURE(status)) { delete en_us; en_us = 0; @@ -370,7 +370,7 @@ void CollationRegressionTest::Test4062418(/* char* par */) RuleBasedCollator *c = nullptr; - c = (RuleBasedCollator *) Collator::createInstance(Locale::getCanadaFrench(), status); + c = dynamic_cast(Collator::createInstance(Locale::getCanadaFrench(), status)); if (c == nullptr || U_FAILURE(status)) { @@ -450,7 +450,7 @@ void CollationRegressionTest::Test4066696(/* char* par */) UErrorCode status = U_ZERO_ERROR; RuleBasedCollator *c = nullptr; - c = (RuleBasedCollator *)Collator::createInstance(Locale::getCanadaFrench(), status); + c = dynamic_cast(Collator::createInstance(Locale::getCanadaFrench(), status)); if (c == nullptr || U_FAILURE(status)) { @@ -599,7 +599,7 @@ void CollationRegressionTest::Test4087241(/* char* par */) Locale da_DK("da", "DK"); RuleBasedCollator *c = nullptr; - c = (RuleBasedCollator *) Collator::createInstance(da_DK, status); + c = dynamic_cast(Collator::createInstance(da_DK, status)); if (c == nullptr || U_FAILURE(status)) { diff --git a/icu4c/source/test/intltest/regextst.cpp b/icu4c/source/test/intltest/regextst.cpp index d124a593524..1489617f998 100644 --- a/icu4c/source/test/intltest/regextst.cpp +++ b/icu4c/source/test/intltest/regextst.cpp @@ -2030,7 +2030,7 @@ void RegexTest::API_Match_UTF8() { //const char str_0123456789[] = { 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x00 }; /* 0123456789 */ // Test shallow-clone API int64_t group_len; - result = matcher->group((UText *)nullptr, group_len, status); + result = matcher->group(nullptr, group_len, status); REGEX_CHECK_STATUS; REGEX_ASSERT_UTEXT_UTF8(str_0123456789, result); utext_close(result); @@ -4697,7 +4697,7 @@ struct callBackContext { U_CDECL_BEGIN static UBool U_CALLCONV testCallBackFn(const void *context, int32_t steps) { - callBackContext *info = (callBackContext *)context; + callBackContext *info = static_cast(const_cast(context)); if (info->lastSteps+1 != steps) { info->test->errln("incorrect steps in callback. Expected %d, got %d\n", info->lastSteps+1, steps); } diff --git a/icu4c/source/test/intltest/scientificnumberformattertest.cpp b/icu4c/source/test/intltest/scientificnumberformattertest.cpp index bacbfba7884..76cf60a96da 100644 --- a/icu4c/source/test/intltest/scientificnumberformattertest.cpp +++ b/icu4c/source/test/intltest/scientificnumberformattertest.cpp @@ -117,7 +117,7 @@ void ScientificNumberFormatterTest::TestFarsi() { void ScientificNumberFormatterTest::TestPlusSignInExponentMarkup() { UErrorCode status = U_ZERO_ERROR; - LocalPointer decfmt((DecimalFormat *) NumberFormat::createScientificInstance("en", status)); + LocalPointer decfmt(dynamic_cast(NumberFormat::createScientificInstance("en", status))); if (U_FAILURE(status)) { dataerrln("Failed call NumberFormat::createScientificInstance(\"en\", status) - %s", u_errorName(status)); return; @@ -144,7 +144,7 @@ void ScientificNumberFormatterTest::TestPlusSignInExponentMarkup() { void ScientificNumberFormatterTest::TestPlusSignInExponentSuperscript() { UErrorCode status = U_ZERO_ERROR; - LocalPointer decfmt((DecimalFormat *) NumberFormat::createScientificInstance("en", status)); + LocalPointer decfmt(dynamic_cast(NumberFormat::createScientificInstance("en", status))); if (U_FAILURE(status)) { dataerrln("Failed call NumberFormat::createScientificInstance(\"en\", status) - %s", u_errorName(status)); return; @@ -171,7 +171,7 @@ void ScientificNumberFormatterTest::TestPlusSignInExponentSuperscript() { void ScientificNumberFormatterTest::TestFixedDecimalMarkup() { UErrorCode status = U_ZERO_ERROR; - LocalPointer decfmt((DecimalFormat *) NumberFormat::createInstance("en", status)); + LocalPointer decfmt(dynamic_cast(NumberFormat::createInstance("en", status))); if (assertSuccess("NumberFormat::createInstance", status, true) == false) { return; } @@ -193,7 +193,7 @@ void ScientificNumberFormatterTest::TestFixedDecimalMarkup() { void ScientificNumberFormatterTest::TestFixedDecimalSuperscript() { UErrorCode status = U_ZERO_ERROR; - LocalPointer decfmt((DecimalFormat *) NumberFormat::createInstance("en", status)); + LocalPointer decfmt(dynamic_cast(NumberFormat::createInstance("en", status))); if (assertSuccess("NumberFormat::createInstance", status, true) == false) { return; } diff --git a/icu4c/source/test/intltest/srchtest.cpp b/icu4c/source/test/intltest/srchtest.cpp index 67fb29f84a2..98fb65fef8a 100644 --- a/icu4c/source/test/intltest/srchtest.cpp +++ b/icu4c/source/test/intltest/srchtest.cpp @@ -48,10 +48,10 @@ StringSearchTest::StringSearchTest() #if !UCONFIG_NO_BREAK_ITERATION UErrorCode status = U_ZERO_ERROR; - m_en_us_ = (RuleBasedCollator *)Collator::createInstance("en_US", status); - m_fr_fr_ = (RuleBasedCollator *)Collator::createInstance("fr_FR", status); - m_de_ = (RuleBasedCollator *)Collator::createInstance("de_DE", status); - m_es_ = (RuleBasedCollator *)Collator::createInstance("es_ES", status); + m_en_us_ = dynamic_cast(Collator::createInstance("en_US", status)); + m_fr_fr_ = dynamic_cast(Collator::createInstance("fr_FR", status)); + m_de_ = dynamic_cast(Collator::createInstance("de_DE", status)); + m_es_ = dynamic_cast(Collator::createInstance("es_ES", status)); if(U_FAILURE(status)) { delete m_en_us_; delete m_fr_fr_; @@ -67,7 +67,7 @@ StringSearchTest::StringSearchTest() UnicodeString rules; - rules.setTo(((RuleBasedCollator *)m_de_)->getRules()); + rules.setTo(m_de_->getRules()); char16_t extrarules[128]; u_unescape(EXTRACOLLATIONRULE, extrarules, 128); rules.append(extrarules, u_strlen(extrarules)); @@ -75,7 +75,7 @@ StringSearchTest::StringSearchTest() m_de_ = new RuleBasedCollator(rules, status); - rules.setTo(((RuleBasedCollator *)m_es_)->getRules()); + rules.setTo(m_es_->getRules()); rules.append(extrarules, u_strlen(extrarules)); delete m_es_; @@ -487,7 +487,7 @@ UBool StringSearchTest::assertEqual(const SearchData *search) } #endif collator->setStrength(getECollationStrength(search->strength)); - strsrch = new StringSearch(pattern, text, (RuleBasedCollator *)collator, + strsrch = new StringSearch(pattern, text, dynamic_cast(collator), breaker, status); if (U_FAILURE(status)) { errln("Error opening string search %s", u_errorName(status)); @@ -547,7 +547,7 @@ UBool StringSearchTest::assertCanonicalEqual(const SearchData *search) #endif collator->setStrength(getECollationStrength(search->strength)); collator->setAttribute(UCOL_NORMALIZATION_MODE, UCOL_ON, status); - strsrch = new StringSearch(pattern, text, (RuleBasedCollator *)collator, + strsrch = new StringSearch(pattern, text, dynamic_cast(collator), breaker, status); strsrch->setAttribute(USEARCH_CANONICAL_MATCH, USEARCH_ON, status); if (U_FAILURE(status)) { @@ -599,7 +599,7 @@ UBool StringSearchTest::assertEqualWithAttribute(const SearchData *search, } #endif collator->setStrength(getECollationStrength(search->strength)); - strsrch = new StringSearch(pattern, text, (RuleBasedCollator *)collator, + strsrch = new StringSearch(pattern, text, dynamic_cast(collator), breaker, status); strsrch->setAttribute(USEARCH_CANONICAL_MATCH, canonical, status); strsrch->setAttribute(USEARCH_OVERLAP, overlap, status); diff --git a/icu4c/source/test/intltest/ssearch.cpp b/icu4c/source/test/intltest/ssearch.cpp index a583ab48d6e..105932a0a84 100644 --- a/icu4c/source/test/intltest/ssearch.cpp +++ b/icu4c/source/test/intltest/ssearch.cpp @@ -626,7 +626,7 @@ void SSearchTest::offsetTest() int32_t testCount = UPRV_LENGTHOF(test); UErrorCode status = U_ZERO_ERROR; - RuleBasedCollator *col = (RuleBasedCollator *) Collator::createInstance(Locale::getEnglish(), status); + RuleBasedCollator *col = dynamic_cast(Collator::createInstance(Locale::getEnglish(), status)); if (U_FAILURE(status)) { errcheckln(status, "Failed to create collator in offsetTest! - %s", u_errorName(status)); return; diff --git a/icu4c/source/test/intltest/strcase.cpp b/icu4c/source/test/intltest/strcase.cpp index af220d316cb..367de44bf3f 100644 --- a/icu4c/source/test/intltest/strcase.cpp +++ b/icu4c/source/test/intltest/strcase.cpp @@ -440,7 +440,7 @@ StringCaseTest::TestCasingImpl(const UnicodeString &input, #if !UCONFIG_NO_BREAK_ITERATION case TEST_TITLE: name="toTitle"; - result.toTitle((BreakIterator *)iter, locale, options); + result.toTitle(static_cast(iter), locale, options); break; #endif case TEST_FOLD: @@ -458,7 +458,7 @@ StringCaseTest::TestCasingImpl(const UnicodeString &input, #if !UCONFIG_NO_BREAK_ITERATION if(whichCase==TEST_TITLE && options==0) { result=input; - result.toTitle((BreakIterator *)iter, locale); + result.toTitle(static_cast(iter), locale); if(result!=output) { dataerrln("error: UnicodeString.toTitle(options=0) got a wrong result for a test case from casing.res"); } @@ -475,7 +475,7 @@ StringCaseTest::TestCasingImpl(const UnicodeString &input, #if !UCONFIG_NO_BREAK_ITERATION if(iter!=nullptr) { // Clone the break iterator so that the UCaseMap can safely adopt it. - UBreakIterator *clone=ubrk_safeClone((UBreakIterator *)iter, nullptr, nullptr, errorCode); + UBreakIterator *clone=ubrk_safeClone(static_cast(iter), nullptr, nullptr, errorCode); ucasemap_setBreakIterator(csm.getAlias(), clone, errorCode); } #endif diff --git a/icu4c/source/test/intltest/svccoll.cpp b/icu4c/source/test/intltest/svccoll.cpp index 04b2ee1c678..38b039e3d47 100644 --- a/icu4c/source/test/intltest/svccoll.cpp +++ b/icu4c/source/test/intltest/svccoll.cpp @@ -241,7 +241,7 @@ CollatorInfo::~CollatorInfo() { UnicodeString& CollatorInfo::getDisplayName(const Locale& displayLocale, UnicodeString& name) const { if (displayNames) { - UnicodeString* val = (UnicodeString*)displayNames->get(displayLocale.getName()); + UnicodeString* val = static_cast(displayNames->get(displayLocale.getName())); if (val) { name = *val; return name; diff --git a/icu4c/source/test/intltest/tfsmalls.cpp b/icu4c/source/test/intltest/tfsmalls.cpp index e57fa7251b1..f95a490a8a6 100644 --- a/icu4c/source/test/intltest/tfsmalls.cpp +++ b/icu4c/source/test/intltest/tfsmalls.cpp @@ -87,7 +87,7 @@ void test_FieldPosition_example( void ) int32_t dNumSize = UPRV_LENGTHOF(doubleNum); UErrorCode status = U_ZERO_ERROR; - DecimalFormat* fmt = (DecimalFormat*) NumberFormat::createInstance(status); + DecimalFormat* fmt = dynamic_cast(NumberFormat::createInstance(status)); if (U_FAILURE(status)) { it_dataerrln("NumberFormat::createInstance() error"); return; diff --git a/icu4c/source/test/intltest/thcoll.cpp b/icu4c/source/test/intltest/thcoll.cpp index 1ebb85fe0e6..a170a886158 100644 --- a/icu4c/source/test/intltest/thcoll.cpp +++ b/icu4c/source/test/intltest/thcoll.cpp @@ -377,7 +377,7 @@ void CollationThaiTest::TestInvalidThai(void) { return; } - CollationElementIterator* c = ((RuleBasedCollator *)coll)->createCollationElementIterator( iteratorText ); + CollationElementIterator* c = (dynamic_cast(coll))->createCollationElementIterator( iteratorText ); for(i = 0; i < UPRV_LENGTHOF(tests); i++) { len = u_unescape(tests[i], strings[i], 20); diff --git a/icu4c/source/test/intltest/tmsgfmt.cpp b/icu4c/source/test/intltest/tmsgfmt.cpp index 06e090d6a13..082c0cad37a 100644 --- a/icu4c/source/test/intltest/tmsgfmt.cpp +++ b/icu4c/source/test/intltest/tmsgfmt.cpp @@ -139,7 +139,7 @@ void TestMessageFormat::testBug3() logln(locale[i].getDisplayName(buffer)); UErrorCode success = U_ZERO_ERROR; // form = (DecimalFormat*)NumberFormat::createCurrencyInstance(locale[i], success); - form = (DecimalFormat*)NumberFormat::createInstance(locale[i], success); + form = dynamic_cast(NumberFormat::createInstance(locale[i], success)); if (U_FAILURE(success)) { errln("Err: Number Format "); logln("Number format creation failed."); diff --git a/icu4c/source/test/intltest/transapi.cpp b/icu4c/source/test/intltest/transapi.cpp index 424e3431d81..9ebdb943536 100644 --- a/icu4c/source/test/intltest/transapi.cpp +++ b/icu4c/source/test/intltest/transapi.cpp @@ -807,7 +807,7 @@ void TransliteratorAPITest::TestGetAdoptFilter(){ doTest(message, got, exp); logln("Testing round trip"); - t->adoptFilter((UnicodeFilter*)u); + t->adoptFilter(const_cast(u)); if(t->getFilter() == nullptr) logln("OK: adoptFilter and getFilter round trip worked"); else diff --git a/icu4c/source/test/intltest/transrt.cpp b/icu4c/source/test/intltest/transrt.cpp index 23eb813ae2a..418c4852a31 100644 --- a/icu4c/source/test/intltest/transrt.cpp +++ b/icu4c/source/test/intltest/transrt.cpp @@ -544,7 +544,7 @@ void RTTest::test2(UBool quickRt, int32_t density) { TransliteratorPointer sourceToTarget( Transliterator::createInstance(transliteratorID, UTRANS_FORWARD, parseError, status)); - if ((Transliterator *)sourceToTarget == nullptr) { + if (sourceToTarget == nullptr) { parent->dataerrln("FAIL: createInstance(" + transliteratorID + ") returned nullptr. Error: " + u_errorName(status) + "\n\tpreContext : " + prettify(parseError.preContext) @@ -553,7 +553,7 @@ void RTTest::test2(UBool quickRt, int32_t density) { return; } TransliteratorPointer targetToSource(sourceToTarget->createInverse(status)); - if ((Transliterator *)targetToSource == nullptr) { + if (targetToSource == nullptr) { parent->errln("FAIL: " + transliteratorID + ".createInverse() returned nullptr. Error:" + u_errorName(status) + "\n\tpreContext : " + prettify(parseError.preContext) @@ -1332,7 +1332,7 @@ void TransliteratorRoundTripTest::TestDevanagariLatin() { UErrorCode status = U_ZERO_ERROR; UParseError parseError; TransliteratorPointer t1(Transliterator::createInstance("[\\u0964-\\u0965\\u0981-\\u0983\\u0985-\\u098C\\u098F-\\u0990\\u0993-\\u09A8\\u09AA-\\u09B0\\u09B2\\u09B6-\\u09B9\\u09BC\\u09BE-\\u09C4\\u09C7-\\u09C8\\u09CB-\\u09CD\\u09D7\\u09DC-\\u09DD\\u09DF-\\u09E3\\u09E6-\\u09FA];NFD;Bengali-InterIndic;InterIndic-Gujarati;NFC;",UTRANS_FORWARD, parseError, status)); - if((Transliterator *)t1 != nullptr){ + if(t1 != nullptr){ TransliteratorPointer t2(t1->createInverse(status)); if(U_FAILURE(status)){ errln("FAIL: could not create the Inverse:-( \n"); diff --git a/icu4c/source/test/intltest/tscoll.cpp b/icu4c/source/test/intltest/tscoll.cpp index 3b294e9944a..ccd59ac6064 100644 --- a/icu4c/source/test/intltest/tscoll.cpp +++ b/icu4c/source/test/intltest/tscoll.cpp @@ -254,7 +254,7 @@ IntlTestCollator::doTest(Collator* col, const UnicodeString &source, const Unico } UErrorCode status = U_ZERO_ERROR; - LocalPointer c(((RuleBasedCollator *)col)->createCollationElementIterator(source)); + LocalPointer c((dynamic_cast(col))->createCollationElementIterator(source)); logln("Testing iterating source: "+source); backAndForth(*c); c->setText(target, status); diff --git a/icu4c/source/test/intltest/tsdate.cpp b/icu4c/source/test/intltest/tsdate.cpp index 1522cf38ec3..37ba1e79b2f 100644 --- a/icu4c/source/test/intltest/tsdate.cpp +++ b/icu4c/source/test/intltest/tsdate.cpp @@ -140,7 +140,7 @@ void IntlTestDateFormat::describeTest() { // Assume it's a SimpleDateFormat and get some info - SimpleDateFormat *s = (SimpleDateFormat*)fFormat; + SimpleDateFormat *s = dynamic_cast(fFormat); UnicodeString str; logln(fTestName + " Pattern " + s->toPattern(str)); } diff --git a/icu4c/source/test/intltest/tsmthred.cpp b/icu4c/source/test/intltest/tsmthred.cpp index 8ba558633cd..27b11730595 100644 --- a/icu4c/source/test/intltest/tsmthred.cpp +++ b/icu4c/source/test/intltest/tsmthred.cpp @@ -1088,7 +1088,7 @@ static std::condition_variable *gCTConditionVar = nullptr; template<> U_EXPORT const UCTMultiThreadItem *LocaleCacheKey::createObject( const void *context, UErrorCode &status) const { - const UnifiedCache *cacheContext = (const UnifiedCache *) context; + const UnifiedCache *cacheContext = static_cast(context); if (uprv_strcmp(fLoc.getLanguage(), fLoc.getName()) != 0) { const UCTMultiThreadItem *result = nullptr; diff --git a/icu4c/source/test/intltest/tsnmfmt.cpp b/icu4c/source/test/intltest/tsnmfmt.cpp index 845206f266e..eee7b099f80 100644 --- a/icu4c/source/test/intltest/tsnmfmt.cpp +++ b/icu4c/source/test/intltest/tsnmfmt.cpp @@ -178,7 +178,7 @@ IntlTestNumberFormat::testFormat(/* char* par */) UnicodeString str; // Assume it's a DecimalFormat and get some info - DecimalFormat *s = (DecimalFormat*)fFormat; + DecimalFormat *s = dynamic_cast(fFormat); logln((UnicodeString)" Pattern " + s->toPattern(str)); #if U_PF_OS390 <= U_PLATFORM && U_PLATFORM <= U_PF_OS400 @@ -422,7 +422,7 @@ void IntlTestNumberFormat::monsterTest(/* char* par */) const char *SEP = "============================================================\n"; int32_t count; const Locale* allLocales = NumberFormat::getAvailableLocales(count); - Locale* locales = (Locale*)allLocales; + Locale* locales = const_cast(allLocales); Locale quickLocales[6]; if (allLocales && count) { diff --git a/icu4c/source/test/intltest/tufmtts.cpp b/icu4c/source/test/intltest/tufmtts.cpp index 742307cf7c1..347f43a7c02 100644 --- a/icu4c/source/test/intltest/tufmtts.cpp +++ b/icu4c/source/test/intltest/tufmtts.cpp @@ -134,7 +134,7 @@ void TimeUnitTest::testBasic() { UnicodeString formatted; Formattable formattable; formattable.adoptObject(source); - formatted = ((Format*)formats[style])->format(formattable, formatted, status); + formatted = (dynamic_cast(formats[style]))->format(formattable, formatted, status); if (!assertSuccess("format()", status)) return; #ifdef TUFMTTS_DEBUG char formatResult[1000]; @@ -142,16 +142,16 @@ void TimeUnitTest::testBasic() { std::cout << "format result: " << formatResult << "\n"; #endif Formattable result; - ((Format*)formats[style])->parseObject(formatted, result, status); + (dynamic_cast(formats[style]))->parseObject(formatted, result, status); if (!assertSuccess("parseObject()", status)) return; - if (!tmaEqual(*((TimeUnitAmount *)result.getObject()), *((TimeUnitAmount *) formattable.getObject()))) { + if (!tmaEqual(*(dynamic_cast(result.getObject())), *(dynamic_cast(formattable.getObject())))) { dataerrln("No round trip: "); } // other style parsing Formattable result_1; - ((Format*)formats[1-style])->parseObject(formatted, result_1, status); + (dynamic_cast(formats[1-style]))->parseObject(formatted, result_1, status); if (!assertSuccess("parseObject()", status)) return; - if (!tmaEqual(*((TimeUnitAmount *)result_1.getObject()), *((TimeUnitAmount *) formattable.getObject()))) { + if (!tmaEqual(*(dynamic_cast(result_1.getObject())), *(dynamic_cast(formattable.getObject())))) { dataerrln("No round trip: "); } } @@ -410,7 +410,7 @@ void TimeUnitTest::testGreekWithFallback() { UnicodeString str; fmt.adoptObject(tamt.orphan()); - str = ((Format *)tfmt.getAlias())->format(fmt, str, status); + str = (dynamic_cast(tfmt.getAlias()))->format(fmt, str, status); if (!assertSuccess("formatting relative time failed", status)) { #ifdef TUFMTTS_DEBUG std::cout << "Failed to format" << "\n"; @@ -469,7 +469,7 @@ void TimeUnitTest::test10219Plurals() { dataerrln("generating TimeUnitFormat Object failed: %s", u_errorName(status)); return; } - LocalPointer nf((DecimalFormat *) NumberFormat::createInstance(usLocale, status)); + LocalPointer nf(dynamic_cast(NumberFormat::createInstance(usLocale, status))); if (U_FAILURE(status)) { dataerrln("generating NumberFormat Object failed: %s", u_errorName(status)); return; diff --git a/icu4c/source/test/intltest/tzfmttst.cpp b/icu4c/source/test/intltest/tzfmttst.cpp index 052f4915dea..fed6218f457 100644 --- a/icu4c/source/test/intltest/tzfmttst.cpp +++ b/icu4c/source/test/intltest/tzfmttst.cpp @@ -275,7 +275,7 @@ TimeZoneFormatTest::TestTimeZoneRoundTrip(void) { status = U_ZERO_ERROR; } else if (outtzid != canonical) { // Canonical ID did not match - check the rules - if (!((BasicTimeZone*)&outtz)->hasEquivalentTransitions((BasicTimeZone&)*tz, low, high, true, status)) { + if (!(dynamic_cast(&outtz))->hasEquivalentTransitions(dynamic_cast(*tz), low, high, true, status)) { if (canonical.indexOf((char16_t)0x27 /*'/'*/) == -1) { // Exceptional cases, such as CET, EET, MET and WET logln((UnicodeString)"Canonical round trip failed (as expected); tz=" + *tzid @@ -613,7 +613,7 @@ void TimeZoneFormatTest::RunTimeRoundTripTests(int32_t threadNumber) { continue; } - BasicTimeZone *tz = (BasicTimeZone*) TimeZone::createTimeZone(*tzid); + BasicTimeZone *tz = dynamic_cast(TimeZone::createTimeZone(*tzid)); sdf->setTimeZone(*tz); UDate t = gLocaleData->START_TIME; diff --git a/icu4c/source/test/intltest/tzoffloc.cpp b/icu4c/source/test/intltest/tzoffloc.cpp index b28a0c5bb18..8990e3cba31 100644 --- a/icu4c/source/test/intltest/tzoffloc.cpp +++ b/icu4c/source/test/intltest/tzoffloc.cpp @@ -131,7 +131,7 @@ TimeZoneOffsetLocalTest::TestGetOffsetAroundTransition() { // Set up TimeZone objects - OlsonTimeZone, SimpleTimeZone and RuleBasedTimeZone BasicTimeZone *TESTZONES[NUM_TIMEZONES]; - TESTZONES[0] = (BasicTimeZone*)TimeZone::createTimeZone("America/Los_Angeles"); + TESTZONES[0] = dynamic_cast(TimeZone::createTimeZone("America/Los_Angeles")); TESTZONES[1] = new SimpleTimeZone(-8*HOUR, "Simple Pacific Time", UCAL_APRIL, 1, UCAL_SUNDAY, 2*HOUR, UCAL_OCTOBER, -1, UCAL_SUNDAY, 2*HOUR, status); diff --git a/icu4c/source/test/intltest/tzregts.cpp b/icu4c/source/test/intltest/tzregts.cpp index 14183c93db9..95fc1b55bc5 100644 --- a/icu4c/source/test/intltest/tzregts.cpp +++ b/icu4c/source/test/intltest/tzregts.cpp @@ -316,7 +316,7 @@ void TimeZoneRegressionTest:: Test4096952() { */ void TimeZoneRegressionTest:: Test4109314() { UErrorCode status = U_ZERO_ERROR; - GregorianCalendar *testCal = (GregorianCalendar*)Calendar::createInstance(status); + GregorianCalendar *testCal = dynamic_cast(Calendar::createInstance(status)); if(U_FAILURE(status)) { dataerrln("Error creating calendar %s", u_errorName(status)); delete testCal; @@ -911,7 +911,7 @@ TimeZoneRegressionTest::Test4162593() } for(int32_t j = 0; j < 3; j++) { - TimeZone *tz = (TimeZone*)DATA_TZ[j]; + TimeZone *tz = DATA_TZ[j]; TimeZone::setDefault(*tz); fmt->setTimeZone(*tz); diff --git a/icu4c/source/test/intltest/tzrulets.cpp b/icu4c/source/test/intltest/tzrulets.cpp index 47f06322096..504874fa70c 100644 --- a/icu4c/source/test/intltest/tzrulets.cpp +++ b/icu4c/source/test/intltest/tzrulets.cpp @@ -428,7 +428,7 @@ TimeZoneRuleTest::TestHistoricalRuleBasedTimeZone(void) { UErrorCode status = U_ZERO_ERROR; // Compare to America/New_York with equivalent RBTZ - BasicTimeZone *ny = (BasicTimeZone*)TimeZone::createTimeZone("America/New_York"); + BasicTimeZone *ny = dynamic_cast(TimeZone::createTimeZone("America/New_York")); //RBTZ InitialTimeZoneRule *ir = new InitialTimeZoneRule("EST", -5*HOUR, 0); @@ -617,7 +617,7 @@ TimeZoneRuleTest::TestOlsonTransition(void) { errln("FAIL: error returned while enumerating timezone IDs."); break; } - BasicTimeZone *tz = (BasicTimeZone*)TimeZone::createTimeZone(*tzid); + BasicTimeZone *tz = dynamic_cast(TimeZone::createTimeZone(*tzid)); for (int32_t i = 0; TESTYEARS[i][0] != 0 || TESTYEARS[i][1] != 0; i++) { UDate lo = getUTCMillis(TESTYEARS[i][0], UCAL_JANUARY, 1); UDate hi = getUTCMillis(TESTYEARS[i][1], UCAL_JANUARY, 1); @@ -652,7 +652,7 @@ TimeZoneRuleTest::TestRBTZTransition(void) { errln("FAIL: error returned while enumerating timezone IDs."); break; } - BasicTimeZone *tz = (BasicTimeZone*)TimeZone::createTimeZone(*tzid); + BasicTimeZone *tz = dynamic_cast(TimeZone::createTimeZone(*tzid)); int32_t ruleCount = tz->countTransitionRules(status); const InitialTimeZoneRule *initial; @@ -701,9 +701,9 @@ TimeZoneRuleTest::TestHasEquivalentTransitions(void) { // America/New_York and America/Indiana/Indianapolis are equivalent // since 2006 UErrorCode status = U_ZERO_ERROR; - BasicTimeZone *newyork = (BasicTimeZone*)TimeZone::createTimeZone("America/New_York"); - BasicTimeZone *indianapolis = (BasicTimeZone*)TimeZone::createTimeZone("America/Indiana/Indianapolis"); - BasicTimeZone *gmt_5 = (BasicTimeZone*)TimeZone::createTimeZone("Etc/GMT+5"); + BasicTimeZone *newyork = dynamic_cast(TimeZone::createTimeZone("America/New_York")); + BasicTimeZone *indianapolis = dynamic_cast(TimeZone::createTimeZone("America/Indiana/Indianapolis")); + BasicTimeZone *gmt_5 = dynamic_cast(TimeZone::createTimeZone("Etc/GMT+5")); UDate jan1_1971 = getUTCMillis(1971, UCAL_JANUARY, 1); UDate jan1_2005 = getUTCMillis(2005, UCAL_JANUARY, 1); @@ -754,7 +754,7 @@ TimeZoneRuleTest::TestHasEquivalentTransitions(void) { // America/New_York and America/Los_Angeles has same DST start rules, but // raw offsets are different - BasicTimeZone *losangeles = (BasicTimeZone*)TimeZone::createTimeZone("America/Los_Angeles"); + BasicTimeZone *losangeles = dynamic_cast(TimeZone::createTimeZone("America/Los_Angeles")); if (newyork->hasEquivalentTransitions(*losangeles, jan1_2006, jan1_2011, true, status)) { dataerrln("FAIL: New_York is not equivalent to Los Angeles, but returned true"); } @@ -789,7 +789,7 @@ TimeZoneRuleTest::TestVTimeZoneRoundTrip(void) { errln("FAIL: error returned while enumerating timezone IDs."); break; } - BasicTimeZone *tz = (BasicTimeZone*)TimeZone::createTimeZone(*tzid); + BasicTimeZone *tz = dynamic_cast(TimeZone::createTimeZone(*tzid)); VTimeZone *vtz_org = VTimeZone::createVTimeZoneByID(*tzid); vtz_org->setTZURL("http://source.icu-project.org/timezone"); vtz_org->setLastModified(Calendar::getNow()); @@ -889,7 +889,7 @@ TimeZoneRuleTest::TestVTimeZoneRoundTripPartial(void) { errln("FAIL: error returned while enumerating timezone IDs."); break; } - BasicTimeZone *tz = (BasicTimeZone*)TimeZone::createTimeZone(*tzid); + BasicTimeZone *tz = dynamic_cast(TimeZone::createTimeZone(*tzid)); VTimeZone *vtz_org = VTimeZone::createVTimeZoneByID(*tzid); VTimeZone *vtz_new = nullptr; UnicodeString vtzdata; @@ -1125,7 +1125,7 @@ TimeZoneRuleTest::TestGetSimpleRules(void) { errln("FAIL: error returned while enumerating timezone IDs."); break; } - BasicTimeZone *tz = (BasicTimeZone*)TimeZone::createTimeZone(*tzid); + BasicTimeZone *tz = dynamic_cast(TimeZone::createTimeZone(*tzid)); initial = nullptr; std = dst = nullptr; tz->getSimpleRulesNear(testTimes[i], initial, std, dst, status); @@ -1618,7 +1618,7 @@ TimeZoneRuleTest::TestVTimeZoneCoverage(void) { UErrorCode status = U_ZERO_ERROR; UnicodeString TZID("Europe/Moscow"); - BasicTimeZone *otz = (BasicTimeZone*)TimeZone::createTimeZone(TZID); + BasicTimeZone *otz = dynamic_cast(TimeZone::createTimeZone(TZID)); VTimeZone *vtz = VTimeZone::createVTimeZoneByID(TZID); // getOffset(era, year, month, day, dayOfWeek, milliseconds, ec) diff --git a/icu4c/source/test/intltest/tztest.cpp b/icu4c/source/test/intltest/tztest.cpp index b439c55d0a0..eebe71815b7 100644 --- a/icu4c/source/test/intltest/tztest.cpp +++ b/icu4c/source/test/intltest/tztest.cpp @@ -110,7 +110,7 @@ TimeZoneTest::TestGenericAPI() SimpleTimeZone copy(*zone); if (!(copy == *zone)) errln("FAIL: copy constructor or operator== failed"); - copy = *(SimpleTimeZone*)zoneclone; + copy = *dynamic_cast(zoneclone); if (!(copy == *zoneclone)) errln("FAIL: assignment operator or operator== failed"); TimeZone* saveDefault = TimeZone::createDefault(); diff --git a/icu4c/source/test/intltest/ucaconf.cpp b/icu4c/source/test/intltest/ucaconf.cpp index 7a8347c7edc..845b153f35c 100644 --- a/icu4c/source/test/intltest/ucaconf.cpp +++ b/icu4c/source/test/intltest/ucaconf.cpp @@ -29,7 +29,7 @@ rbUCA(nullptr), testFile(nullptr), status(U_ZERO_ERROR) { - UCA = (RuleBasedCollator *)Collator::createInstance(Locale::getRoot(), status); + UCA = dynamic_cast(Collator::createInstance(Locale::getRoot(), status)); if(U_FAILURE(status)) { dataerrln("Error - UCAConformanceTest: Unable to open UCA collator! - %s", u_errorName(status)); } diff --git a/icu4c/source/test/intltest/ucdtest.cpp b/icu4c/source/test/intltest/ucdtest.cpp index 503340e051c..c28541e2a66 100644 --- a/icu4c/source/test/intltest/ucdtest.cpp +++ b/icu4c/source/test/intltest/ucdtest.cpp @@ -172,7 +172,7 @@ derivedPropsLineFn(void *context, char *fields[][2], int32_t /* fieldCount */, UErrorCode *pErrorCode) { - UnicodeTest *me=(UnicodeTest *)context; + UnicodeTest *me=static_cast(context); uint32_t start, end; int32_t i; diff --git a/icu4c/source/test/intltest/unifiedcachetest.cpp b/icu4c/source/test/intltest/unifiedcachetest.cpp index f3164ac4328..6e5352fc6de 100644 --- a/icu4c/source/test/intltest/unifiedcachetest.cpp +++ b/icu4c/source/test/intltest/unifiedcachetest.cpp @@ -34,7 +34,7 @@ U_NAMESPACE_BEGIN template<> U_EXPORT const UCTItem *LocaleCacheKey::createObject( const void *context, UErrorCode &status) const { - const UnifiedCache *cacheContext = (const UnifiedCache *) context; + const UnifiedCache *cacheContext = static_cast(context); if (uprv_strcmp(fLoc.getName(), "zh") == 0) { status = U_MISSING_RESOURCE_ERROR; return nullptr; diff --git a/icu4c/source/test/intltest/units_test.cpp b/icu4c/source/test/intltest/units_test.cpp index 56f56f95d4e..e321c6f0cb5 100644 --- a/icu4c/source/test/intltest/units_test.cpp +++ b/icu4c/source/test/intltest/units_test.cpp @@ -439,7 +439,7 @@ void unitsTestDataLineFn(void *context, char *fields[][2], int32_t fieldCount, U if (U_FAILURE(*pErrorCode)) { return; } - UnitsTestContext *ctx = (UnitsTestContext *)context; + UnitsTestContext *ctx = static_cast(context); UnitsTest *unitsTest = ctx->unitsTest; (void)fieldCount; // unused UParseLineFn variable IcuTestErrorCode status(*unitsTest, "unitsTestDatalineFn"); @@ -902,7 +902,7 @@ void checkOutput(UnitsTest *unitsTest, const char *msg, ExpectedOutput expected, void unitPreferencesTestDataLineFn(void *context, char *fields[][2], int32_t fieldCount, UErrorCode *pErrorCode) { if (U_FAILURE(*pErrorCode)) return; - UnitsTest *unitsTest = (UnitsTest *)context; + UnitsTest *unitsTest = static_cast(context); IcuTestErrorCode status(*unitsTest, "unitPreferencesTestDatalineFn"); if (!unitsTest->assertTrue(u"unitPreferencesTestDataLineFn expects 9 fields for simple and 11 " diff --git a/icu4c/source/test/intltest/usettest.cpp b/icu4c/source/test/intltest/usettest.cpp index f0ed0e49479..5bf3ab12f49 100644 --- a/icu4c/source/test/intltest/usettest.cpp +++ b/icu4c/source/test/intltest/usettest.cpp @@ -1635,7 +1635,7 @@ public: * SymbolTable API */ virtual const UnicodeString* lookup(const UnicodeString& s) const override { - return (const UnicodeString*) contents.get(s); + return static_cast(contents.get(s)); } /** diff --git a/icu4c/source/test/intltest/utxttest.cpp b/icu4c/source/test/intltest/utxttest.cpp index e9bc2c8f72f..d966975d767 100644 --- a/icu4c/source/test/intltest/utxttest.cpp +++ b/icu4c/source/test/intltest/utxttest.cpp @@ -1264,7 +1264,7 @@ void UTextTest::FreezeTest() { TEST_ASSERT(status == U_NO_WRITE_PERMISSION); status = U_ZERO_ERROR; - ut = utext_openConstUnicodeString(ut, (const UnicodeString *)&ustr, &status); + ut = utext_openConstUnicodeString(ut, &ustr, &status); TEST_SUCCESS(status); writable = utext_isWritable(ut); TEST_ASSERT(writable == false); @@ -1311,8 +1311,8 @@ void UTextTest::FreezeTest() { U_CDECL_BEGIN static UBool U_CALLCONV fragTextAccess(UText *ut, int64_t index, UBool forward) { - const UnicodeString *us = (const UnicodeString *)ut->context; - char16_t c; + const UnicodeString *us = static_cast(ut->context); + char16_t c; int32_t length = us->length(); if (forward && index>=0 && indexcharAt((int32_t)index); @@ -1362,7 +1362,7 @@ cloneFragmentedUnicodeString(UText *dest, const UText *src, UBool deep, UErrorCo *status = U_UNSUPPORTED_ERROR; return nullptr; } - dest = utext_openUnicodeString(dest, (UnicodeString *)src->context, status); + dest = utext_openUnicodeString(dest, static_cast(const_cast(src->context)), status); utext_setNativeIndex(dest, utext_getNativeIndex(src)); return dest; }