ICU-22621 Clang-Tidy: readability-delete-null-pointer https://releases.llvm.org/17.0.1/tools/clang/tools/extra/docs/clang-tidy/checks/readability/delete-null-pointer.html
diff --git a/icu4c/source/common/brkeng.cpp b/icu4c/source/common/brkeng.cpp index e6fc7fe..e53a7b2 100644 --- a/icu4c/source/common/brkeng.cpp +++ b/icu4c/source/common/brkeng.cpp
@@ -118,9 +118,7 @@ ICULanguageBreakFactory::ICULanguageBreakFactory(UErrorCode &/*status*/) { } ICULanguageBreakFactory::~ICULanguageBreakFactory() { - if (fEngines != nullptr) { - delete fEngines; - } + delete fEngines; } void ICULanguageBreakFactory::ensureEngines(UErrorCode& status) {
diff --git a/icu4c/source/common/caniter.cpp b/icu4c/source/common/caniter.cpp index a3ab521..2c98730 100644 --- a/icu4c/source/common/caniter.cpp +++ b/icu4c/source/common/caniter.cpp
@@ -253,9 +253,7 @@ void CanonicalIterator::setSource(const UnicodeString &newSource, UErrorCode &st return; // Common section to cleanup all local variables and reset object variables. CleanPartialInitialization: - if (list != nullptr) { - delete[] list; - } + delete[] list; cleanPieces(); }
diff --git a/icu4c/source/common/resbund.cpp b/icu4c/source/common/resbund.cpp index 94c3251..41337cd 100644 --- a/icu4c/source/common/resbund.cpp +++ b/icu4c/source/common/resbund.cpp
@@ -241,9 +241,7 @@ ResourceBundle::~ResourceBundle() if (fResource != nullptr) { ures_close(fResource); } - if(fLocale != nullptr) { - delete(fLocale); - } + delete fLocale; } ResourceBundle *
diff --git a/icu4c/source/i18n/dtfmtsym.cpp b/icu4c/source/i18n/dtfmtsym.cpp index ccebc5e..2c1c21c 100644 --- a/icu4c/source/i18n/dtfmtsym.cpp +++ b/icu4c/source/i18n/dtfmtsym.cpp
@@ -918,9 +918,7 @@ DateFormatSymbols::setYearNames(const UnicodeString* yearNames, int32_t count, DtContextType context, DtWidthType width) { if (context == FORMAT && width == ABBREVIATED) { - if (fShortYearNames) { - delete[] fShortYearNames; - } + delete[] fShortYearNames; fShortYearNames = newUnicodeStringArray(count); uprv_arrayCopy(yearNames, fShortYearNames, count); fShortYearNamesCount = count; @@ -940,9 +938,7 @@ DateFormatSymbols::setZodiacNames(const UnicodeString* zodiacNames, int32_t coun DtContextType context, DtWidthType width) { if (context == FORMAT && width == ABBREVIATED) { - if (fShortZodiacNames) { - delete[] fShortZodiacNames; - } + delete[] fShortZodiacNames; fShortZodiacNames = newUnicodeStringArray(count); uprv_arrayCopy(zodiacNames, fShortZodiacNames, count); fShortZodiacNamesCount = count; @@ -955,8 +951,7 @@ void DateFormatSymbols::setEras(const UnicodeString* erasArray, int32_t count) { // delete the old list if we own it - if (fEras) - delete[] fEras; + delete[] fEras; // we always own the new list, which we create here (we duplicate rather // than adopting the list passed in) @@ -969,8 +964,7 @@ void DateFormatSymbols::setEraNames(const UnicodeString* eraNamesArray, int32_t count) { // delete the old list if we own it - if (fEraNames) - delete[] fEraNames; + delete[] fEraNames; // we always own the new list, which we create here (we duplicate rather // than adopting the list passed in) @@ -983,8 +977,7 @@ void DateFormatSymbols::setNarrowEras(const UnicodeString* narrowErasArray, int32_t count) { // delete the old list if we own it - if (fNarrowEras) - delete[] fNarrowEras; + delete[] fNarrowEras; // we always own the new list, which we create here (we duplicate rather // than adopting the list passed in) @@ -997,8 +990,7 @@ void DateFormatSymbols::setMonths(const UnicodeString* monthsArray, int32_t count) { // delete the old list if we own it - if (fMonths) - delete[] fMonths; + delete[] fMonths; // we always own the new list, which we create here (we duplicate rather // than adopting the list passed in) @@ -1011,8 +1003,7 @@ void DateFormatSymbols::setShortMonths(const UnicodeString* shortMonthsArray, int32_t count) { // delete the old list if we own it - if (fShortMonths) - delete[] fShortMonths; + delete[] fShortMonths; // we always own the new list, which we create here (we duplicate rather // than adopting the list passed in) @@ -1032,22 +1023,19 @@ DateFormatSymbols::setMonths(const UnicodeString* monthsArray, int32_t count, Dt case FORMAT : switch (width) { case WIDE : - if (fMonths) - delete[] fMonths; + delete[] fMonths; fMonths = newUnicodeStringArray(count); uprv_arrayCopy( monthsArray,fMonths,count); fMonthsCount = count; break; case ABBREVIATED : - if (fShortMonths) - delete[] fShortMonths; + delete[] fShortMonths; fShortMonths = newUnicodeStringArray(count); uprv_arrayCopy( monthsArray,fShortMonths,count); fShortMonthsCount = count; break; case NARROW : - if (fNarrowMonths) - delete[] fNarrowMonths; + delete[] fNarrowMonths; fNarrowMonths = newUnicodeStringArray(count); uprv_arrayCopy( monthsArray,fNarrowMonths,count); fNarrowMonthsCount = count; @@ -1059,22 +1047,19 @@ DateFormatSymbols::setMonths(const UnicodeString* monthsArray, int32_t count, Dt case STANDALONE : switch (width) { case WIDE : - if (fStandaloneMonths) - delete[] fStandaloneMonths; + delete[] fStandaloneMonths; fStandaloneMonths = newUnicodeStringArray(count); uprv_arrayCopy( monthsArray,fStandaloneMonths,count); fStandaloneMonthsCount = count; break; case ABBREVIATED : - if (fStandaloneShortMonths) - delete[] fStandaloneShortMonths; + delete[] fStandaloneShortMonths; fStandaloneShortMonths = newUnicodeStringArray(count); uprv_arrayCopy( monthsArray,fStandaloneShortMonths,count); fStandaloneShortMonthsCount = count; break; case NARROW : - if (fStandaloneNarrowMonths) - delete[] fStandaloneNarrowMonths; + delete[] fStandaloneNarrowMonths; fStandaloneNarrowMonths = newUnicodeStringArray(count); uprv_arrayCopy( monthsArray,fStandaloneNarrowMonths,count); fStandaloneNarrowMonthsCount = count; @@ -1091,8 +1076,7 @@ DateFormatSymbols::setMonths(const UnicodeString* monthsArray, int32_t count, Dt void DateFormatSymbols::setWeekdays(const UnicodeString* weekdaysArray, int32_t count) { // delete the old list if we own it - if (fWeekdays) - delete[] fWeekdays; + delete[] fWeekdays; // we always own the new list, which we create here (we duplicate rather // than adopting the list passed in) @@ -1105,8 +1089,7 @@ void DateFormatSymbols::setShortWeekdays(const UnicodeString* shortWeekdaysArray, int32_t count) { // delete the old list if we own it - if (fShortWeekdays) - delete[] fShortWeekdays; + delete[] fShortWeekdays; // we always own the new list, which we create here (we duplicate rather // than adopting the list passed in) @@ -1126,29 +1109,25 @@ DateFormatSymbols::setWeekdays(const UnicodeString* weekdaysArray, int32_t count case FORMAT : switch (width) { case WIDE : - if (fWeekdays) - delete[] fWeekdays; + delete[] fWeekdays; fWeekdays = newUnicodeStringArray(count); uprv_arrayCopy(weekdaysArray, fWeekdays, count); fWeekdaysCount = count; break; case ABBREVIATED : - if (fShortWeekdays) - delete[] fShortWeekdays; + delete[] fShortWeekdays; fShortWeekdays = newUnicodeStringArray(count); uprv_arrayCopy(weekdaysArray, fShortWeekdays, count); fShortWeekdaysCount = count; break; case SHORT : - if (fShorterWeekdays) - delete[] fShorterWeekdays; + delete[] fShorterWeekdays; fShorterWeekdays = newUnicodeStringArray(count); uprv_arrayCopy(weekdaysArray, fShorterWeekdays, count); fShorterWeekdaysCount = count; break; case NARROW : - if (fNarrowWeekdays) - delete[] fNarrowWeekdays; + delete[] fNarrowWeekdays; fNarrowWeekdays = newUnicodeStringArray(count); uprv_arrayCopy(weekdaysArray, fNarrowWeekdays, count); fNarrowWeekdaysCount = count; @@ -1160,29 +1139,25 @@ DateFormatSymbols::setWeekdays(const UnicodeString* weekdaysArray, int32_t count case STANDALONE : switch (width) { case WIDE : - if (fStandaloneWeekdays) - delete[] fStandaloneWeekdays; + delete[] fStandaloneWeekdays; fStandaloneWeekdays = newUnicodeStringArray(count); uprv_arrayCopy(weekdaysArray, fStandaloneWeekdays, count); fStandaloneWeekdaysCount = count; break; case ABBREVIATED : - if (fStandaloneShortWeekdays) - delete[] fStandaloneShortWeekdays; + delete[] fStandaloneShortWeekdays; fStandaloneShortWeekdays = newUnicodeStringArray(count); uprv_arrayCopy(weekdaysArray, fStandaloneShortWeekdays, count); fStandaloneShortWeekdaysCount = count; break; case SHORT : - if (fStandaloneShorterWeekdays) - delete[] fStandaloneShorterWeekdays; + delete[] fStandaloneShorterWeekdays; fStandaloneShorterWeekdays = newUnicodeStringArray(count); uprv_arrayCopy(weekdaysArray, fStandaloneShorterWeekdays, count); fStandaloneShorterWeekdaysCount = count; break; case NARROW : - if (fStandaloneNarrowWeekdays) - delete[] fStandaloneNarrowWeekdays; + delete[] fStandaloneNarrowWeekdays; fStandaloneNarrowWeekdays = newUnicodeStringArray(count); uprv_arrayCopy(weekdaysArray, fStandaloneNarrowWeekdays, count); fStandaloneNarrowWeekdaysCount = count; @@ -1207,22 +1182,19 @@ DateFormatSymbols::setQuarters(const UnicodeString* quartersArray, int32_t count case FORMAT : switch (width) { case WIDE : - if (fQuarters) - delete[] fQuarters; + delete[] fQuarters; fQuarters = newUnicodeStringArray(count); uprv_arrayCopy( quartersArray,fQuarters,count); fQuartersCount = count; break; case ABBREVIATED : - if (fShortQuarters) - delete[] fShortQuarters; + delete[] fShortQuarters; fShortQuarters = newUnicodeStringArray(count); uprv_arrayCopy( quartersArray,fShortQuarters,count); fShortQuartersCount = count; break; case NARROW : - if (fNarrowQuarters) - delete[] fNarrowQuarters; + delete[] fNarrowQuarters; fNarrowQuarters = newUnicodeStringArray(count); uprv_arrayCopy( quartersArray,fNarrowQuarters,count); fNarrowQuartersCount = count; @@ -1234,22 +1206,19 @@ DateFormatSymbols::setQuarters(const UnicodeString* quartersArray, int32_t count case STANDALONE : switch (width) { case WIDE : - if (fStandaloneQuarters) - delete[] fStandaloneQuarters; + delete[] fStandaloneQuarters; fStandaloneQuarters = newUnicodeStringArray(count); uprv_arrayCopy( quartersArray,fStandaloneQuarters,count); fStandaloneQuartersCount = count; break; case ABBREVIATED : - if (fStandaloneShortQuarters) - delete[] fStandaloneShortQuarters; + delete[] fStandaloneShortQuarters; fStandaloneShortQuarters = newUnicodeStringArray(count); uprv_arrayCopy( quartersArray,fStandaloneShortQuarters,count); fStandaloneShortQuartersCount = count; break; case NARROW : - if (fStandaloneNarrowQuarters) - delete[] fStandaloneNarrowQuarters; + delete[] fStandaloneNarrowQuarters; fStandaloneNarrowQuarters = newUnicodeStringArray(count); uprv_arrayCopy( quartersArray,fStandaloneNarrowQuarters,count); fStandaloneNarrowQuartersCount = count; @@ -1267,7 +1236,7 @@ void DateFormatSymbols::setAmPmStrings(const UnicodeString* amPmsArray, int32_t count) { // delete the old list if we own it - if (fAmPms) delete[] fAmPms; + delete[] fAmPms; // we always own the new list, which we create here (we duplicate rather // than adopting the list passed in) @@ -1383,12 +1352,8 @@ DateFormatSymbols::initZoneStringsArray() { } } - if (tzNames) { - delete tzNames; - } - if (tzids) { - delete tzids; - } + delete tzNames; + delete tzids; fLocaleZoneStrings = zarray; fZoneStringsRowCount = rows;
diff --git a/icu4c/source/i18n/dtptngen.cpp b/icu4c/source/i18n/dtptngen.cpp index 9a2cb5d..132b3e7 100644 --- a/icu4c/source/i18n/dtptngen.cpp +++ b/icu4c/source/i18n/dtptngen.cpp
@@ -463,15 +463,12 @@ DateTimePatternGenerator::operator!=(const DateTimePatternGenerator& other) cons } DateTimePatternGenerator::~DateTimePatternGenerator() { - if (fAvailableFormatKeyHash!=nullptr) { - delete fAvailableFormatKeyHash; - } - - if (fp != nullptr) delete fp; - if (dtMatcher != nullptr) delete dtMatcher; - if (distanceInfo != nullptr) delete distanceInfo; - if (patternMap != nullptr) delete patternMap; - if (skipMatcher != nullptr) delete skipMatcher; + delete fAvailableFormatKeyHash; + delete fp; + delete dtMatcher; + delete distanceInfo; + delete patternMap; + delete skipMatcher; } namespace {
diff --git a/icu4c/source/i18n/fmtable.cpp b/icu4c/source/i18n/fmtable.cpp index 65dafc9..01d7bad 100644 --- a/icu4c/source/i18n/fmtable.cpp +++ b/icu4c/source/i18n/fmtable.cpp
@@ -775,9 +775,7 @@ Formattable::populateDecimalQuantity(number::impl::DecimalQuantity& output, UErr // --------------------------------------- void Formattable::adoptDecimalQuantity(DecimalQuantity *dq) { - if (fDecimalQuantity != nullptr) { - delete fDecimalQuantity; - } + delete fDecimalQuantity; fDecimalQuantity = dq; if (dq == nullptr) { // allow adoptDigitList(nullptr) to clear return;
diff --git a/icu4c/source/i18n/measunit.cpp b/icu4c/source/i18n/measunit.cpp index abb2199..a70d486 100644 --- a/icu4c/source/i18n/measunit.cpp +++ b/icu4c/source/i18n/measunit.cpp
@@ -2169,9 +2169,7 @@ MeasureUnit &MeasureUnit::operator=(const MeasureUnit &other) { if (this == &other) { return *this; } - if (fImpl != nullptr) { - delete fImpl; - } + delete fImpl; if (other.fImpl) { ErrorCode localStatus; fImpl = new MeasureUnitImpl(other.fImpl->copy(localStatus)); @@ -2192,9 +2190,7 @@ MeasureUnit &MeasureUnit::operator=(MeasureUnit &&other) noexcept { if (this == &other) { return *this; } - if (fImpl != nullptr) { - delete fImpl; - } + delete fImpl; fImpl = other.fImpl; other.fImpl = nullptr; fTypeId = other.fTypeId;
diff --git a/icu4c/source/i18n/number_multiplier.cpp b/icu4c/source/i18n/number_multiplier.cpp index dd5b3f8..e6bc2a1 100644 --- a/icu4c/source/i18n/number_multiplier.cpp +++ b/icu4c/source/i18n/number_multiplier.cpp
@@ -66,9 +66,7 @@ Scale::Scale(Scale&& src) noexcept Scale& Scale::operator=(Scale&& src) noexcept { fMagnitude = src.fMagnitude; - if (fArbitrary != nullptr) { - delete fArbitrary; - } + delete fArbitrary; fArbitrary = src.fArbitrary; fError = src.fError; // Take ownership away from src if necessary
diff --git a/icu4c/source/i18n/olsontz.cpp b/icu4c/source/i18n/olsontz.cpp index c4a4189..924502f 100644 --- a/icu4c/source/i18n/olsontz.cpp +++ b/icu4c/source/i18n/olsontz.cpp
@@ -664,18 +664,10 @@ OlsonTimeZone::clearTransitionRules() { void OlsonTimeZone::deleteTransitionRules() { - if (initialRule != nullptr) { - delete initialRule; - } - if (firstTZTransition != nullptr) { - delete firstTZTransition; - } - if (firstFinalTZTransition != nullptr) { - delete firstFinalTZTransition; - } - if (finalZoneWithStartYear != nullptr) { - delete finalZoneWithStartYear; - } + delete initialRule; + delete firstTZTransition; + delete firstFinalTZTransition; + delete finalZoneWithStartYear; if (historicRules != nullptr) { for (int i = 0; i < historicRuleCount; i++) { if (historicRules[i] != nullptr) {
diff --git a/icu4c/source/i18n/plurfmt.cpp b/icu4c/source/i18n/plurfmt.cpp index 33a539c..7b225bc 100644 --- a/icu4c/source/i18n/plurfmt.cpp +++ b/icu4c/source/i18n/plurfmt.cpp
@@ -149,13 +149,8 @@ PluralFormat::PluralFormat(const PluralFormat& other) void PluralFormat::copyObjects(const PluralFormat& other) { UErrorCode status = U_ZERO_ERROR; - if (numberFormat != nullptr) { - delete numberFormat; - } - if (pluralRulesWrapper.pluralRules != nullptr) { - delete pluralRulesWrapper.pluralRules; - } - + delete numberFormat; + delete pluralRulesWrapper.pluralRules; if (other.numberFormat == nullptr) { numberFormat = NumberFormat::createInstance(locale, status); } else {
diff --git a/icu4c/source/i18n/rbnf.cpp b/icu4c/source/i18n/rbnf.cpp index e3ebced..66854d5 100644 --- a/icu4c/source/i18n/rbnf.cpp +++ b/icu4c/source/i18n/rbnf.cpp
@@ -1923,10 +1923,7 @@ RuleBasedNumberFormat::adoptDecimalFormatSymbols(DecimalFormatSymbols* symbolsTo return; // do not allow caller to set decimalFormatSymbols to nullptr } - if (decimalFormatSymbols != nullptr) { - delete decimalFormatSymbols; - } - + delete decimalFormatSymbols; decimalFormatSymbols = symbolsToAdopt; {
diff --git a/icu4c/source/i18n/rbtz.cpp b/icu4c/source/i18n/rbtz.cpp index e4d7143..6bee2aa 100644 --- a/icu4c/source/i18n/rbtz.cpp +++ b/icu4c/source/i18n/rbtz.cpp
@@ -635,9 +635,7 @@ RuleBasedTimeZone::deleteRules() { void RuleBasedTimeZone::deleteTransitions() { - if (fHistoricTransitions != nullptr) { - delete fHistoricTransitions; - } + delete fHistoricTransitions; fHistoricTransitions = nullptr; }
diff --git a/icu4c/source/i18n/region.cpp b/icu4c/source/i18n/region.cpp index 26440b6..839a252 100644 --- a/icu4c/source/i18n/region.cpp +++ b/icu4c/source/i18n/region.cpp
@@ -455,12 +455,8 @@ Region::Region () } Region::~Region () { - if (containedRegions) { - delete containedRegions; - } - if (preferredValues) { - delete preferredValues; - } + delete containedRegions; + delete preferredValues; } /**
diff --git a/icu4c/source/i18n/rematch.cpp b/icu4c/source/i18n/rematch.cpp index 7a39afbf..c3566c0 100644 --- a/icu4c/source/i18n/rematch.cpp +++ b/icu4c/source/i18n/rematch.cpp
@@ -165,9 +165,7 @@ RegexMatcher::~RegexMatcher() { fPattern = nullptr; } - if (fInput) { - delete fInput; - } + delete fInput; if (fInputText) { utext_close(fInputText); }
diff --git a/icu4c/source/i18n/repattrn.cpp b/icu4c/source/i18n/repattrn.cpp index e4faf68..0573789 100644 --- a/icu4c/source/i18n/repattrn.cpp +++ b/icu4c/source/i18n/repattrn.cpp
@@ -233,9 +233,7 @@ void RegexPattern::zap() { for (i=1; i<fSets->size(); i++) { UnicodeSet *s; s = (UnicodeSet *)fSets->elementAt(i); - if (s != nullptr) { - delete s; - } + delete s; } delete fSets; fSets = nullptr;
diff --git a/icu4c/source/i18n/simpletz.cpp b/icu4c/source/i18n/simpletz.cpp index 56be94b..f144577 100644 --- a/icu4c/source/i18n/simpletz.cpp +++ b/icu4c/source/i18n/simpletz.cpp
@@ -1054,18 +1054,10 @@ SimpleTimeZone::clearTransitionRules() { void SimpleTimeZone::deleteTransitionRules() { - if (initialRule != nullptr) { - delete initialRule; - } - if (firstTransition != nullptr) { - delete firstTransition; - } - if (stdRule != nullptr) { - delete stdRule; - } - if (dstRule != nullptr) { - delete dstRule; - } + delete initialRule; + delete firstTransition; + delete stdRule; + delete dstRule; clearTransitionRules(); }
diff --git a/icu4c/source/i18n/smpdtfmt.cpp b/icu4c/source/i18n/smpdtfmt.cpp index 05afdbb..383c134 100644 --- a/icu4c/source/i18n/smpdtfmt.cpp +++ b/icu4c/source/i18n/smpdtfmt.cpp
@@ -332,9 +332,7 @@ SimpleDateFormat::~SimpleDateFormat() if (fSharedNumberFormatters) { freeSharedNumberFormatters(fSharedNumberFormatters); } - if (fTimeZoneFormat) { - delete fTimeZoneFormat; - } + delete fTimeZoneFormat; delete fSimpleNumberFormatter; #if !UCONFIG_NO_BREAK_ITERATION @@ -1114,9 +1112,7 @@ SimpleDateFormat::_format(Calendar& cal, UnicodeString& appendTo, prevCh, handler, *workCal, status); } - if (calClone != nullptr) { - delete calClone; - } + delete calClone; return appendTo; } @@ -2656,12 +2652,8 @@ SimpleDateFormat::parse(const UnicodeString& text, Calendar& cal, ParsePosition& cal.setTime(workCal->getTime(status), status); } - if (numericLeapMonthFormatter != nullptr) { - delete numericLeapMonthFormatter; - } - if (calClone != nullptr) { - delete calClone; - } + delete numericLeapMonthFormatter; + delete calClone; // If any Calendar calls failed, we pretend that we // couldn't parse the string, when in reality this isn't quite accurate--
diff --git a/icu4c/source/i18n/translit.cpp b/icu4c/source/i18n/translit.cpp index d368a3d..4225614 100644 --- a/icu4c/source/i18n/translit.cpp +++ b/icu4c/source/i18n/translit.cpp
@@ -140,9 +140,7 @@ Transliterator::Transliterator(const UnicodeString& theID, * Destructor. */ Transliterator::~Transliterator() { - if (filter) { - delete filter; - } + delete filter; } /**
diff --git a/icu4c/source/i18n/tzfmt.cpp b/icu4c/source/i18n/tzfmt.cpp index 2785146..00c69ee 100644 --- a/icu4c/source/i18n/tzfmt.cpp +++ b/icu4c/source/i18n/tzfmt.cpp
@@ -157,15 +157,11 @@ U_CDECL_BEGIN */ static UBool U_CALLCONV tzfmt_cleanup() { - if (gZoneIdTrie != nullptr) { - delete gZoneIdTrie; - } + delete gZoneIdTrie; gZoneIdTrie = nullptr; gZoneIdTrieInitOnce.reset(); - if (gShortZoneIdTrie != nullptr) { - delete gShortZoneIdTrie; - } + delete gShortZoneIdTrie; gShortZoneIdTrie = nullptr; gShortZoneIdTrieInitOnce.reset();
diff --git a/icu4c/source/i18n/tzgnames.cpp b/icu4c/source/i18n/tzgnames.cpp index edc200b..19ad3840 100644 --- a/icu4c/source/i18n/tzgnames.cpp +++ b/icu4c/source/i18n/tzgnames.cpp
@@ -144,9 +144,7 @@ TimeZoneGenericNameMatchInfo::TimeZoneGenericNameMatchInfo(UVector* matches) } TimeZoneGenericNameMatchInfo::~TimeZoneGenericNameMatchInfo() { - if (fMatches != nullptr) { - delete fMatches; - } + delete fMatches; } int32_t @@ -208,9 +206,7 @@ GNameSearchHandler::GNameSearchHandler(uint32_t types) } GNameSearchHandler::~GNameSearchHandler() { - if (fResults != nullptr) { - delete fResults; - } + delete fResults; } UBool @@ -430,12 +426,8 @@ TZGNCore::initialize(const Locale& locale, UErrorCode& status) { void TZGNCore::cleanup() { - if (fLocaleDisplayNames != nullptr) { - delete fLocaleDisplayNames; - } - if (fTimeZoneNames != nullptr) { - delete fTimeZoneNames; - } + delete fLocaleDisplayNames; + delete fTimeZoneNames; uhash_close(fLocationNamesMap); uhash_close(fPartialLocationNamesMap); @@ -869,9 +861,7 @@ TZGNCore::loadStrings(const UnicodeString& tzCanonicalID) { } } } - if (mzIDs != nullptr) { - delete mzIDs; - } + delete mzIDs; } int32_t @@ -1026,9 +1016,7 @@ TZGNCore::findLocal(const UnicodeString& text, int32_t start, uint32_t types, UE return gmatchInfo; } - if (results != nullptr) { - delete results; - } + delete results; // All names are not yet loaded into the local trie. // Load all available names into the trie. This could be very heavy. @@ -1045,9 +1033,7 @@ TZGNCore::findLocal(const UnicodeString& text, int32_t start, uint32_t types, UE nonConstThis->loadStrings(*tzID); } } - if (tzIDs != nullptr) { - delete tzIDs; - } + delete tzIDs; if (U_SUCCESS(status)) { nonConstThis->fGNamesTrieFullyLoaded = true; @@ -1242,9 +1228,7 @@ TimeZoneGenericNames::createInstance(const Locale& locale, UErrorCode& status) { } } if (U_FAILURE(status)) { - if (tzgnCore != nullptr) { - delete tzgnCore; - } + delete tzgnCore; if (newKey != nullptr) { uprv_free(newKey); }
diff --git a/icu4c/source/i18n/tznames.cpp b/icu4c/source/i18n/tznames.cpp index e734b14..24ca161 100644 --- a/icu4c/source/i18n/tznames.cpp +++ b/icu4c/source/i18n/tznames.cpp
@@ -182,9 +182,7 @@ TimeZoneNamesDelegate::TimeZoneNamesDelegate(const Locale& locale, UErrorCode& s } } if (U_FAILURE(status)) { - if (tznames != nullptr) { - delete tznames; - } + delete tznames; if (newKey != nullptr) { uprv_free(newKey); } @@ -403,9 +401,7 @@ TimeZoneNames::MatchInfoCollection::MatchInfoCollection() } TimeZoneNames::MatchInfoCollection::~MatchInfoCollection() { - if (fMatches != nullptr) { - delete fMatches; - } + delete fMatches; } void
diff --git a/icu4c/source/i18n/tznames_impl.cpp b/icu4c/source/i18n/tznames_impl.cpp index 5e25947..6ac7afa 100644 --- a/icu4c/source/i18n/tznames_impl.cpp +++ b/icu4c/source/i18n/tznames_impl.cpp
@@ -947,9 +947,7 @@ ZNameSearchHandler::ZNameSearchHandler(uint32_t types) } ZNameSearchHandler::~ZNameSearchHandler() { - if (fResults != nullptr) { - delete fResults; - } + delete fResults; } UBool @@ -1699,9 +1697,7 @@ void TimeZoneNamesImpl::internalLoadAllDisplayNames(UErrorCode& status) { } } } - if (tzIDs != nullptr) { - delete tzIDs; - } + delete tzIDs; } } @@ -1933,9 +1929,7 @@ TZDBNameSearchHandler::TZDBNameSearchHandler(uint32_t types, StringPiece region) } TZDBNameSearchHandler::~TZDBNameSearchHandler() { - if (fResults != nullptr) { - delete fResults; - } + delete fResults; } UBool
diff --git a/icu4c/source/i18n/tztrans.cpp b/icu4c/source/i18n/tztrans.cpp index dbce342..45e1678 100644 --- a/icu4c/source/i18n/tztrans.cpp +++ b/icu4c/source/i18n/tztrans.cpp
@@ -40,12 +40,8 @@ TimeZoneTransition::TimeZoneTransition(const TimeZoneTransition& source) } TimeZoneTransition::~TimeZoneTransition() { - if (fFrom != nullptr) { - delete fFrom; - } - if (fTo != nullptr) { - delete fTo; - } + delete fFrom; + delete fTo; } TimeZoneTransition* @@ -96,33 +92,25 @@ TimeZoneTransition::setTime(UDate time) { void TimeZoneTransition::setFrom(const TimeZoneRule& from) { - if (fFrom != nullptr) { - delete fFrom; - } + delete fFrom; fFrom = from.clone(); } void TimeZoneTransition::adoptFrom(TimeZoneRule* from) { - if (fFrom != nullptr) { - delete fFrom; - } + delete fFrom; fFrom = from; } void TimeZoneTransition::setTo(const TimeZoneRule& to) { - if (fTo != nullptr) { - delete fTo; - } + delete fTo; fTo = to.clone(); } void TimeZoneTransition::adoptTo(TimeZoneRule* to) { - if (fTo != nullptr) { - delete fTo; - } + delete fTo; fTo = to; }
diff --git a/icu4c/source/i18n/vtzone.cpp b/icu4c/source/i18n/vtzone.cpp index 25af556..31ad09c 100644 --- a/icu4c/source/i18n/vtzone.cpp +++ b/icu4c/source/i18n/vtzone.cpp
@@ -985,12 +985,8 @@ VTimeZone::VTimeZone(const VTimeZone& source) } VTimeZone::~VTimeZone() { - if (tz != nullptr) { - delete tz; - } - if (vtzlines != nullptr) { - delete vtzlines; - } + delete tz; + delete vtzlines; } VTimeZone& @@ -2132,12 +2128,8 @@ VTimeZone::writeZone(VTZWriter& w, BasicTimeZone& basictz, cleanupWriteZone: - if (finalStdRule != nullptr) { - delete finalStdRule; - } - if (finalDstRule != nullptr) { - delete finalDstRule; - } + delete finalStdRule; + delete finalDstRule; } void
diff --git a/icu4c/source/samples/layout/gnomelayout.cpp b/icu4c/source/samples/layout/gnomelayout.cpp index ea1e0d6..0a7a5ff 100644 --- a/icu4c/source/samples/layout/gnomelayout.cpp +++ b/icu4c/source/samples/layout/gnomelayout.cpp
@@ -103,9 +103,7 @@ void openOK(GtkObject */*object*/, gpointer data) gchar *title = prettyTitle(fileName); GtkWidget *area = GTK_WIDGET(gtk_object_get_data(GTK_OBJECT(app), "area")); - if (context->paragraph != nullptr) { - delete context->paragraph; - } + delete context->paragraph; context->paragraph = newPara; gtk_window_set_title(GTK_WINDOW(app), title); @@ -287,9 +285,7 @@ void closeSample(GtkWidget *app) { Context *context = (Context *) gtk_object_get_data(GTK_OBJECT(app), "context"); - if (context->paragraph != nullptr) { - delete context->paragraph; - } + delete context->paragraph; delete context;
diff --git a/icu4c/source/test/intltest/aliastst.cpp b/icu4c/source/test/intltest/aliastst.cpp index 6a055eb..90b3db2 100644 --- a/icu4c/source/test/intltest/aliastst.cpp +++ b/icu4c/source/test/intltest/aliastst.cpp
@@ -278,12 +278,8 @@ void LocaleAliasTest::TestUResourceBundle() { log(" new:"); logln(us2); - if (rb1!=nullptr) { - delete rb1; - } - if (rb2!=nullptr) { - delete rb2; - } + delete rb1; + delete rb2; } }
diff --git a/icu4c/source/test/intltest/allcoll.cpp b/icu4c/source/test/intltest/allcoll.cpp index efff800..fa5efef 100644 --- a/icu4c/source/test/intltest/allcoll.cpp +++ b/icu4c/source/test/intltest/allcoll.cpp
@@ -32,10 +32,7 @@ CollationDummyTest::CollationDummyTest() UErrorCode status = U_ZERO_ERROR; UnicodeString ruleset("& C < ch, cH, Ch, CH & Five, 5 & Four, 4 & one, 1 & Ampersand; '&' & Two, 2 "); - if (myCollation != nullptr) - { - delete myCollation; - } + delete myCollation; myCollation = new RuleBasedCollator(ruleset, status); if(U_FAILURE(status)){ errcheckln(status, "ERROR: in creation of rule based collator from ruleset - %s", u_errorName(status));
diff --git a/icu4c/source/test/intltest/canittst.cpp b/icu4c/source/test/intltest/canittst.cpp index 41fafb2..ebb457d 100644 --- a/icu4c/source/test/intltest/canittst.cpp +++ b/icu4c/source/test/intltest/canittst.cpp
@@ -60,12 +60,8 @@ nameTrans(nullptr), hexTrans(nullptr) CanonicalIteratorTest::~CanonicalIteratorTest() { #if !UCONFIG_NO_TRANSLITERATION - if(nameTrans != nullptr) { delete(nameTrans); - } - if(hexTrans != nullptr) { delete(hexTrans); - } #endif }
diff --git a/icu4c/source/test/intltest/dtfmttst.cpp b/icu4c/source/test/intltest/dtfmttst.cpp index ee1fc2c..9cf2cc7 100644 --- a/icu4c/source/test/intltest/dtfmttst.cpp +++ b/icu4c/source/test/intltest/dtfmttst.cpp
@@ -274,9 +274,7 @@ void DateFormatTest::TestWallyWedel() StringEnumeration* ids = TimeZone::createEnumeration(status); if (U_FAILURE(status)) { dataerrln("Unable to create TimeZone enumeration."); - if (sdf != nullptr) { - delete sdf; - } + delete sdf; return; } ids_length = ids->count(status); @@ -3996,9 +3994,7 @@ void DateFormatTest::TestISOEra() { SimpleDateFormat *fmt1 = new SimpleDateFormat(UnicodeString("GGG yyyy-MM-dd'T'HH:mm:ss'Z"), status); failure(status, "new SimpleDateFormat", true); if (status == U_MISSING_RESOURCE_ERROR) { - if (fmt1 != nullptr) { - delete fmt1; - } + delete fmt1; return; } for(int i=0; i < numData; i+=2) { @@ -4314,14 +4310,10 @@ void DateFormatTest::TestContext() ", expected " + itemPtr->expectedFormat + ", got " + result); } } - if (sdmft) { - delete sdmft; - } + delete sdmft; } } - if (cal) { - delete cal; - } + delete cal; } // test item for a particular locale + calendar and date format
diff --git a/icu4c/source/test/intltest/srchtest.cpp b/icu4c/source/test/intltest/srchtest.cpp index 0824808..d8abe9d 100644 --- a/icu4c/source/test/intltest/srchtest.cpp +++ b/icu4c/source/test/intltest/srchtest.cpp
@@ -925,9 +925,7 @@ void StringSearchTest::TestBreakIterator() if (U_FAILURE(status) || strsrch->getBreakIterator() != breaker) { errln("Error setting break iterator"); - if (strsrch != nullptr) { - delete strsrch; - } + delete strsrch; } if (!assertEqualWithStringSearch(strsrch, search)) { collator->setStrength(getECollationStrength(UCOL_TERTIARY)); @@ -1128,9 +1126,7 @@ void StringSearchTest::TestPattern() if (U_FAILURE(status)) { errln("Error opening string search %s", u_errorName(status)); m_en_us_->setStrength(getECollationStrength(UCOL_TERTIARY)); - if (strsrch != nullptr) { - delete strsrch; - } + delete strsrch; return; } if (strsrch->getPattern() != pattern) { @@ -1138,9 +1134,7 @@ void StringSearchTest::TestPattern() } if (!assertEqualWithStringSearch(strsrch, &PATTERN[0])) { m_en_us_->setStrength(getECollationStrength(UCOL_TERTIARY)); - if (strsrch != nullptr) { - delete strsrch; - } + delete strsrch; return; } @@ -1150,9 +1144,7 @@ void StringSearchTest::TestPattern() if (pattern != strsrch->getPattern()) { errln("Error setting pattern"); m_en_us_->setStrength(getECollationStrength(UCOL_TERTIARY)); - if (strsrch != nullptr) { - delete strsrch; - } + delete strsrch; return; } strsrch->reset(); @@ -1161,9 +1153,7 @@ void StringSearchTest::TestPattern() } if (!assertEqualWithStringSearch(strsrch, &PATTERN[1])) { m_en_us_->setStrength(getECollationStrength(UCOL_TERTIARY)); - if (strsrch != nullptr) { - delete strsrch; - } + delete strsrch; return; } @@ -1173,9 +1163,7 @@ void StringSearchTest::TestPattern() if (pattern != strsrch->getPattern()) { errln("Error setting pattern"); m_en_us_->setStrength(getECollationStrength(UCOL_TERTIARY)); - if (strsrch != nullptr) { - delete strsrch; - } + delete strsrch; return; } strsrch->reset(); @@ -1184,9 +1172,7 @@ void StringSearchTest::TestPattern() } if (!assertEqualWithStringSearch(strsrch, &PATTERN[0])) { m_en_us_->setStrength(getECollationStrength(UCOL_TERTIARY)); - if (strsrch != nullptr) { - delete strsrch; - } + delete strsrch; return; } /* enormous pattern size to see if this crashes */ @@ -1200,9 +1186,7 @@ void StringSearchTest::TestPattern() errln("Error setting pattern with size 512, %s", u_errorName(status)); } m_en_us_->setStrength(getECollationStrength(UCOL_TERTIARY)); - if (strsrch != nullptr) { - delete strsrch; - } + delete strsrch; } void StringSearchTest::TestText() @@ -1431,9 +1415,7 @@ void StringSearchTest::TestGetMatch() status); if (U_FAILURE(status)) { errln("Error opening string search %s", u_errorName(status)); - if (strsrch != nullptr) { - delete strsrch; - } + delete strsrch; return; } @@ -1494,9 +1476,7 @@ void StringSearchTest::TestSetMatch() nullptr, status); if (U_FAILURE(status)) { errln("Error opening string search %s", u_errorName(status)); - if (strsrch != nullptr) { - delete strsrch; - } + delete strsrch; return; } @@ -1554,9 +1534,7 @@ void StringSearchTest::TestReset() status); if (U_FAILURE(status)) { errln("Error opening string search %s", u_errorName(status)); - if (strsrch != nullptr) { - delete strsrch; - } + delete strsrch; return; } strsrch->setAttribute(USEARCH_OVERLAP, USEARCH_ON, status); @@ -1941,9 +1919,7 @@ void StringSearchTest::TestCollatorCanonical() strsrch->setAttribute(USEARCH_CANONICAL_MATCH, USEARCH_ON, status); if (!assertEqualWithStringSearch(strsrch, &COLLATORCANONICAL[1])) { delete strsrch; - if (tailored != nullptr) { - delete tailored; - } + delete tailored; return; } @@ -1956,9 +1932,7 @@ void StringSearchTest::TestCollatorCanonical() if (!assertEqualWithStringSearch(strsrch, &COLLATORCANONICAL[0])) { } delete strsrch; - if (tailored != nullptr) { - delete tailored; - } + delete tailored; } void StringSearchTest::TestPatternCanonical() @@ -2024,9 +1998,7 @@ void StringSearchTest::TestPatternCanonical() } ENDTESTPATTERN: m_en_us_->setStrength(getECollationStrength(UCOL_TERTIARY)); - if (strsrch != nullptr) { - delete strsrch; - } + delete strsrch; } void StringSearchTest::TestTextCanonical() @@ -2083,9 +2055,7 @@ void StringSearchTest::TestTextCanonical() goto ENDTESTPATTERN; } ENDTESTPATTERN: - if (strsrch != nullptr) { - delete strsrch; - } + delete strsrch; } void StringSearchTest::TestCompositeBoundariesCanonical()
diff --git a/icu4c/source/test/intltest/tzrulets.cpp b/icu4c/source/test/intltest/tzrulets.cpp index 14ce88b..e15e3ee 100644 --- a/icu4c/source/test/intltest/tzrulets.cpp +++ b/icu4c/source/test/intltest/tzrulets.cpp
@@ -92,9 +92,7 @@ TestZIDEnumeration::TestZIDEnumeration(UBool all) } TestZIDEnumeration::~TestZIDEnumeration() { - if (tzenum != nullptr) { - delete tzenum; - } + delete tzenum; } const UnicodeString*
diff --git a/icu4c/source/test/perf/ustrperf/stringperf.h b/icu4c/source/test/perf/ustrperf/stringperf.h index 264bbf9..b846ddf 100644 --- a/icu4c/source/test/perf/ustrperf/stringperf.h +++ b/icu4c/source/test/perf/ustrperf/stringperf.h
@@ -70,8 +70,8 @@ class StringPerfFunction : public UPerfFunction virtual long getEventsPerIteration(){ int loops = LOOPS; - if (catICU) { delete catICU;} - if (catStd) { delete catStd;} + delete catICU; + delete catStd; if (bCatenatePrealloc) {
diff --git a/icu4c/source/tools/ctestfw/testdata.cpp b/icu4c/source/tools/ctestfw/testdata.cpp index 2fb9338..ad07ce0 100644 --- a/icu4c/source/tools/ctestfw/testdata.cpp +++ b/icu4c/source/tools/ctestfw/testdata.cpp
@@ -25,15 +25,9 @@ fCurrentCase(0) } TestData::~TestData() { - if(fInfo != nullptr) { - delete fInfo; - } - if(fCurrSettings != nullptr) { - delete fCurrSettings; - } - if(fCurrCase != nullptr) { - delete fCurrCase; - } + delete fInfo; + delete fCurrSettings; + delete fCurrCase; } const char * TestData::getName() const
diff --git a/icu4c/source/tools/ctestfw/tstdtmod.cpp b/icu4c/source/tools/ctestfw/tstdtmod.cpp index 3ebe224..6490651 100644 --- a/icu4c/source/tools/ctestfw/tstdtmod.cpp +++ b/icu4c/source/tools/ctestfw/tstdtmod.cpp
@@ -161,9 +161,7 @@ fLog(log) } TestDataModule::~TestDataModule() { - if(fInfo != nullptr) { - delete fInfo; - } + delete fInfo; } const char * TestDataModule::getName() const
diff --git a/icu4c/source/tools/ctestfw/uperf.cpp b/icu4c/source/tools/ctestfw/uperf.cpp index 9e92b77..ddd36c3 100644 --- a/icu4c/source/tools/ctestfw/uperf.cpp +++ b/icu4c/source/tools/ctestfw/uperf.cpp
@@ -518,9 +518,7 @@ UBool UPerfTest::callTest( UPerfTest& testToBeCalled, char* par ) } UPerfTest::~UPerfTest(){ - if(lines!=nullptr){ - delete[] lines; - } + delete[] lines; if(buffer!=nullptr){ uprv_free(buffer); }
diff --git a/icu4c/source/tools/tzcode/icuzdump.cpp b/icu4c/source/tools/tzcode/icuzdump.cpp index c82fc43..ff073ed 100644 --- a/icu4c/source/tools/tzcode/icuzdump.cpp +++ b/icu4c/source/tools/tzcode/icuzdump.cpp
@@ -233,9 +233,7 @@ class ZoneIterator { } ~ZoneIterator() { - if (zenum != nullptr) { - delete zenum; - } + delete zenum; } TimeZone* next() {