From e017edc97df2dd542b959fc013aa8c2ea1d37448 Mon Sep 17 00:00:00 2001 From: Fredrik Roubert Date: Mon, 18 Mar 2024 17:35:02 +0100 Subject: [PATCH] ICU-22621 Clang-Tidy: readability-qualified-auto https://releases.llvm.org/17.0.1/tools/clang/tools/extra/docs/clang-tidy/checks/readability/qualified-auto.html --- icu4c/source/common/localeprioritylist.cpp | 6 +++--- icu4c/source/common/ucurr.cpp | 2 +- icu4c/source/i18n/datefmt.cpp | 4 ++-- icu4c/source/i18n/decimfmt.cpp | 2 +- icu4c/source/i18n/formatted_string_builder.cpp | 14 ++++++++------ icu4c/source/i18n/measfmt.cpp | 10 +++++----- icu4c/source/i18n/measunit_extra.cpp | 4 ++-- icu4c/source/i18n/msgfmt.cpp | 2 +- icu4c/source/i18n/number_asformat.cpp | 2 +- icu4c/source/i18n/number_capi.cpp | 6 +++--- icu4c/source/i18n/number_compact.cpp | 4 ++-- icu4c/source/i18n/number_decimalquantity.cpp | 2 +- icu4c/source/i18n/number_fluent.cpp | 8 ++++---- icu4c/source/i18n/number_formatimpl.cpp | 13 +++++++------ icu4c/source/i18n/number_mapper.h | 4 ++-- icu4c/source/i18n/number_modifiers.cpp | 10 +++++----- icu4c/source/i18n/number_patternmodifier.cpp | 10 +++++----- icu4c/source/i18n/number_scientific.cpp | 2 +- icu4c/source/i18n/number_simple.cpp | 6 +++--- icu4c/source/i18n/number_skeletons.cpp | 2 +- icu4c/source/i18n/numparse_compositions.cpp | 6 +++--- icu4c/source/i18n/numparse_decimal.cpp | 2 +- icu4c/source/i18n/numrange_capi.cpp | 4 ++-- icu4c/source/i18n/numrange_fluent.cpp | 4 ++-- icu4c/source/i18n/reldatefmt.cpp | 4 ++-- icu4c/source/i18n/smpdtfmt.cpp | 8 ++++---- icu4c/source/i18n/units_converter.cpp | 9 +++++---- icu4c/source/i18n/units_router.cpp | 2 +- icu4c/source/i18n/uspoof_impl.cpp | 2 +- icu4c/source/test/fuzzer/ucasemap_fuzzer.cpp | 2 +- icu4c/source/test/intltest/dcfmapts.cpp | 10 +++++----- icu4c/source/test/intltest/dtptngts.cpp | 4 ++-- icu4c/source/test/intltest/itspoof.cpp | 2 +- icu4c/source/test/intltest/loctest.cpp | 2 +- icu4c/source/test/intltest/measfmttest.cpp | 2 +- icu4c/source/test/intltest/numbertest_api.cpp | 18 +++++++++--------- .../intltest/numbertest_decimalquantity.cpp | 4 ++-- .../source/test/intltest/numbertest_parse.cpp | 8 ++++---- .../test/intltest/numbertest_patternstring.cpp | 2 +- .../source/test/intltest/numbertest_range.cpp | 2 +- icu4c/source/test/intltest/numfmtst.cpp | 8 ++++---- icu4c/source/test/intltest/tmsgfmt.cpp | 2 +- icu4c/source/test/intltest/units_data_test.cpp | 4 ++-- icu4c/source/tools/genrb/filterrb.cpp | 8 ++++---- 44 files changed, 118 insertions(+), 114 deletions(-) diff --git a/icu4c/source/common/localeprioritylist.cpp b/icu4c/source/common/localeprioritylist.cpp index e5ba0a3c777..8ca70b14324 100644 --- a/icu4c/source/common/localeprioritylist.cpp +++ b/icu4c/source/common/localeprioritylist.cpp @@ -21,13 +21,13 @@ U_NAMESPACE_BEGIN namespace { int32_t hashLocale(const UHashTok token) { - auto *locale = static_cast(token.pointer); + const auto* locale = static_cast(token.pointer); return locale->hashCode(); } UBool compareLocales(const UHashTok t1, const UHashTok t2) { - auto *l1 = static_cast(t1.pointer); - auto *l2 = static_cast(t2.pointer); + const auto* l1 = static_cast(t1.pointer); + const auto* l2 = static_cast(t2.pointer); return *l1 == *l2; } diff --git a/icu4c/source/common/ucurr.cpp b/icu4c/source/common/ucurr.cpp index 5c6703777bd..237501bec1a 100644 --- a/icu4c/source/common/ucurr.cpp +++ b/icu4c/source/common/ucurr.cpp @@ -2203,7 +2203,7 @@ static void U_CALLCONV initIsoCodes(UErrorCode &status) { static void populateCurrSymbolsEquiv(icu::Hashtable *hash, UErrorCode &status) { if (U_FAILURE(status)) { return; } - for (auto& entry : unisets::kCurrencyEntries) { + for (const auto& entry : unisets::kCurrencyEntries) { UnicodeString exemplar(entry.exemplar); const UnicodeSet* set = unisets::get(entry.key); if (set == nullptr) { return; } diff --git a/icu4c/source/i18n/datefmt.cpp b/icu4c/source/i18n/datefmt.cpp index c63af128506..42669e1c406 100644 --- a/icu4c/source/i18n/datefmt.cpp +++ b/icu4c/source/i18n/datefmt.cpp @@ -279,7 +279,7 @@ UnicodeString& DateFormat::format(UDate date, UnicodeString& appendTo, FieldPosition& fieldPosition) const { if (fCalendar != nullptr) { UErrorCode ec = U_ZERO_ERROR; - auto calType = fCalendar->getType(); + const auto* calType = fCalendar->getType(); // Avoid a heap allocation and corresponding free for the common case if (uprv_strcmp(calType, "gregorian") == 0) { GregorianCalendar cal(*static_cast(fCalendar)); @@ -309,7 +309,7 @@ DateFormat::format(UDate date, UnicodeString& appendTo, FieldPositionIterator* p UErrorCode& status) const { if (fCalendar != nullptr) { UErrorCode ec = U_ZERO_ERROR; - auto calType = fCalendar->getType(); + const auto* calType = fCalendar->getType(); // Avoid a heap allocation and corresponding free for the common case if (uprv_strcmp(calType, "gregorian") == 0) { GregorianCalendar cal(*static_cast(fCalendar)); diff --git a/icu4c/source/i18n/decimfmt.cpp b/icu4c/source/i18n/decimfmt.cpp index 75906991d72..36c44afe2cc 100644 --- a/icu4c/source/i18n/decimfmt.cpp +++ b/icu4c/source/i18n/decimfmt.cpp @@ -498,7 +498,7 @@ DecimalFormat* DecimalFormat::clone() const { } bool DecimalFormat::operator==(const Format& other) const { - auto* otherDF = dynamic_cast(&other); + const auto* otherDF = dynamic_cast(&other); if (otherDF == nullptr) { return false; } diff --git a/icu4c/source/i18n/formatted_string_builder.cpp b/icu4c/source/i18n/formatted_string_builder.cpp index 102715ee330..6481f73dcf6 100644 --- a/icu4c/source/i18n/formatted_string_builder.cpp +++ b/icu4c/source/i18n/formatted_string_builder.cpp @@ -72,8 +72,8 @@ FormattedStringBuilder &FormattedStringBuilder::operator=(const FormattedStringB if (capacity > DEFAULT_CAPACITY) { // FIXME: uprv_malloc // C++ note: malloc appears in two places: here and in prepareForInsertHelper. - auto newChars = static_cast (uprv_malloc(sizeof(char16_t) * capacity)); - auto newFields = static_cast(uprv_malloc(sizeof(Field) * capacity)); + auto* newChars = static_cast(uprv_malloc(sizeof(char16_t) * capacity)); + auto* newFields = static_cast(uprv_malloc(sizeof(Field) * capacity)); if (newChars == nullptr || newFields == nullptr) { // UErrorCode is not available; fail silently. uprv_free(newChars); @@ -153,8 +153,8 @@ FormattedStringBuilder::insertCodePoint(int32_t index, UChar32 codePoint, Field if (U_FAILURE(status)) { return count; } - auto charPtr = getCharPtr(); - auto fieldPtr = getFieldPtr(); + auto* charPtr = getCharPtr(); + auto* fieldPtr = getFieldPtr(); if (count == 1) { charPtr[position] = (char16_t) codePoint; fieldPtr[position] = field; @@ -308,8 +308,10 @@ int32_t FormattedStringBuilder::prepareForInsertHelper(int32_t index, int32_t co newZero = (newCapacity - newLength) / 2; // C++ note: malloc appears in two places: here and in the assignment operator. - auto newChars = static_cast (uprv_malloc(sizeof(char16_t) * static_cast(newCapacity))); - auto newFields = static_cast(uprv_malloc(sizeof(Field) * static_cast(newCapacity))); + auto* newChars = + static_cast(uprv_malloc(sizeof(char16_t) * static_cast(newCapacity))); + auto* newFields = + static_cast(uprv_malloc(sizeof(Field) * static_cast(newCapacity))); if (newChars == nullptr || newFields == nullptr) { uprv_free(newChars); uprv_free(newFields); diff --git a/icu4c/source/i18n/measfmt.cpp b/icu4c/source/i18n/measfmt.cpp index da4e69b49b7..4e5ea26cfb9 100644 --- a/icu4c/source/i18n/measfmt.cpp +++ b/icu4c/source/i18n/measfmt.cpp @@ -501,14 +501,14 @@ UnicodeString &MeasureFormat::formatMeasurePerUnit( if (U_FAILURE(status)) { return appendTo; } - auto* df = dynamic_cast(&getNumberFormatInternal()); + const auto* df = dynamic_cast(&getNumberFormatInternal()); if (df == nullptr) { // Don't know how to handle other types of NumberFormat status = U_UNSUPPORTED_ERROR; return appendTo; } UFormattedNumberData result; - if (auto* lnf = df->toNumberFormatter(status)) { + if (const auto* lnf = df->toNumberFormatter(status)) { result.quantity.setToDouble(measure.getNumber().getDouble(status)); lnf->unit(measure.getUnit()) .perUnit(perUnit) @@ -691,7 +691,7 @@ UnicodeString &MeasureFormat::formatMeasure( pos, status); } - auto* df = dynamic_cast(&nf); + const auto* df = dynamic_cast(&nf); if (df == nullptr) { // Handle other types of NumberFormat using the ICU 63 code, modified to // get the unitPattern from LongNameHandler and handle fallback to OTHER. @@ -708,7 +708,7 @@ UnicodeString &MeasureFormat::formatMeasure( return QuantityFormatter::format(formatter, formattedNumber, appendTo, pos, status); } UFormattedNumberData result; - if (auto* lnf = df->toNumberFormatter(status)) { + if (const auto* lnf = df->toNumberFormatter(status)) { result.quantity.setToDouble(amtNumber.getDouble(status)); lnf->unit(amtUnit) .unitWidth(getUnitWidth(fWidth)) @@ -761,7 +761,7 @@ UnicodeString &MeasureFormat::formatNumeric( return appendTo; } number::LocalizedNumberFormatter numberFormatter2; - if (auto* lnf = numberFormatter->toNumberFormatter(status)) { + if (const auto* lnf = numberFormatter->toNumberFormatter(status)) { numberFormatter2 = lnf->integerWidth(number::IntegerWidth::zeroFillTo(2)); } else { return appendTo; diff --git a/icu4c/source/i18n/measunit_extra.cpp b/icu4c/source/i18n/measunit_extra.cpp index a8c0ad8c5e6..79b5cbe364f 100644 --- a/icu4c/source/i18n/measunit_extra.cpp +++ b/icu4c/source/i18n/measunit_extra.cpp @@ -801,8 +801,8 @@ private: // Sorting function wrapping SingleUnitImpl::compareTo for use with uprv_sortArray. int32_t U_CALLCONV compareSingleUnits(const void* /*context*/, const void* left, const void* right) { - auto realLeft = static_cast(left); - auto realRight = static_cast(right); + const auto* realLeft = static_cast(left); + const auto* realRight = static_cast(right); return (*realLeft)->compareTo(**realRight); } diff --git a/icu4c/source/i18n/msgfmt.cpp b/icu4c/source/i18n/msgfmt.cpp index d6708409a30..0413dc7465d 100644 --- a/icu4c/source/i18n/msgfmt.cpp +++ b/icu4c/source/i18n/msgfmt.cpp @@ -1983,7 +1983,7 @@ UnicodeString MessageFormat::PluralSelectorProvider::select(void *ctx, double nu return UnicodeString(false, OTHER_STRING, 5); } context.formatter->format(context.number, context.numberString, ec); - auto* decFmt = dynamic_cast(context.formatter); + const auto* decFmt = dynamic_cast(context.formatter); if(decFmt != nullptr) { number::impl::DecimalQuantity dq; decFmt->formatToDecimalQuantity(context.number, dq, ec); diff --git a/icu4c/source/i18n/number_asformat.cpp b/icu4c/source/i18n/number_asformat.cpp index 8f2314d6898..aac765f3fbc 100644 --- a/icu4c/source/i18n/number_asformat.cpp +++ b/icu4c/source/i18n/number_asformat.cpp @@ -33,7 +33,7 @@ LocalizedNumberFormatterAsFormat::LocalizedNumberFormatterAsFormat( LocalizedNumberFormatterAsFormat::~LocalizedNumberFormatterAsFormat() = default; bool LocalizedNumberFormatterAsFormat::operator==(const Format& other) const { - auto* _other = dynamic_cast(&other); + const auto* _other = dynamic_cast(&other); if (_other == nullptr) { return false; } diff --git a/icu4c/source/i18n/number_capi.cpp b/icu4c/source/i18n/number_capi.cpp index bc7dc8c4342..e98c593f4a7 100644 --- a/icu4c/source/i18n/number_capi.cpp +++ b/icu4c/source/i18n/number_capi.cpp @@ -96,7 +96,7 @@ UPRV_FORMATTED_VALUE_CAPI_NO_IMPLTYPE_AUTO_IMPL( const DecimalQuantity* icu::number::impl::validateUFormattedNumberToDecimalQuantity( const UFormattedNumber* uresult, UErrorCode& status) { - auto* result = UFormattedNumberApiHelper::validate(uresult, status); + const auto* result = UFormattedNumberApiHelper::validate(uresult, status); if (U_FAILURE(status)) { return nullptr; } @@ -355,7 +355,7 @@ usnumf_format( USimpleNumber* unumber, UFormattedNumber* uresult, UErrorCode* ec) { - auto* formatter = USimpleNumberFormatterData::validate(uformatter, *ec); + const auto* formatter = USimpleNumberFormatterData::validate(uformatter, *ec); auto* number = USimpleNumberData::validate(unumber, *ec); auto* result = UFormattedNumberApiHelper::validate(uresult, *ec); if (U_FAILURE(*ec)) { @@ -374,7 +374,7 @@ usnumf_formatInt64( int64_t value, UFormattedNumber* uresult, UErrorCode* ec) { - auto* formatter = USimpleNumberFormatterData::validate(uformatter, *ec); + const auto* formatter = USimpleNumberFormatterData::validate(uformatter, *ec); auto* result = UFormattedNumberApiHelper::validate(uresult, *ec); if (U_FAILURE(*ec)) { return; diff --git a/icu4c/source/i18n/number_compact.cpp b/icu4c/source/i18n/number_compact.cpp index 2cfa65a031d..63180f213e2 100644 --- a/icu4c/source/i18n/number_compact.cpp +++ b/icu4c/source/i18n/number_compact.cpp @@ -143,7 +143,7 @@ void CompactData::getUniquePatterns(UVector &output, UErrorCode &status) const { U_ASSERT(output.isEmpty()); // NOTE: In C++, this is done more manually with a UVector. // In Java, we can take advantage of JDK HashSet. - for (auto pattern : patterns) { + for (const auto* pattern : patterns) { if (pattern == nullptr || pattern == USE_FALLBACK) { continue; } @@ -279,7 +279,7 @@ void CompactHandler::precomputeAllModifiers(MutablePatternModifier &buildReferen } for (int32_t i = 0; i < precomputedModsLength; i++) { - auto patternString = static_cast(allPatterns[i]); + const auto* patternString = static_cast(allPatterns[i]); UnicodeString hello(patternString); CompactModInfo &info = precomputedMods[i]; ParsedPatternInfo patternInfo; diff --git a/icu4c/source/i18n/number_decimalquantity.cpp b/icu4c/source/i18n/number_decimalquantity.cpp index 659465d0870..054b97d7c34 100644 --- a/icu4c/source/i18n/number_decimalquantity.cpp +++ b/icu4c/source/i18n/number_decimalquantity.cpp @@ -1322,7 +1322,7 @@ void DecimalQuantity::ensureCapacity(int32_t capacity) { // Initialize the byte array to zeros (this is done automatically in Java) uprv_memset(fBCD.bcdBytes.ptr, 0, capacity * sizeof(int8_t)); } else if (oldCapacity < capacity) { - auto bcd1 = static_cast(uprv_malloc(capacity * 2 * sizeof(int8_t))); + auto* bcd1 = static_cast(uprv_malloc(capacity * 2 * sizeof(int8_t))); uprv_memcpy(bcd1, fBCD.bcdBytes.ptr, oldCapacity * sizeof(int8_t)); // Initialize the rest of the byte array to zeros (this is done automatically in Java) uprv_memset(bcd1 + oldCapacity, 0, (capacity - oldCapacity) * sizeof(int8_t)); diff --git a/icu4c/source/i18n/number_fluent.cpp b/icu4c/source/i18n/number_fluent.cpp index eeb8e1b7f3b..0ce01c854ca 100644 --- a/icu4c/source/i18n/number_fluent.cpp +++ b/icu4c/source/i18n/number_fluent.cpp @@ -573,7 +573,7 @@ LocalizedNumberFormatter UnlocalizedNumberFormatter::locale(const Locale& locale FormattedNumber LocalizedNumberFormatter::formatInt(int64_t value, UErrorCode& status) const { if (U_FAILURE(status)) { return FormattedNumber(U_ILLEGAL_ARGUMENT_ERROR); } - auto results = new UFormattedNumberData(); + auto* results = new UFormattedNumberData(); if (results == nullptr) { status = U_MEMORY_ALLOCATION_ERROR; return FormattedNumber(status); @@ -592,7 +592,7 @@ FormattedNumber LocalizedNumberFormatter::formatInt(int64_t value, UErrorCode& s FormattedNumber LocalizedNumberFormatter::formatDouble(double value, UErrorCode& status) const { if (U_FAILURE(status)) { return FormattedNumber(U_ILLEGAL_ARGUMENT_ERROR); } - auto results = new UFormattedNumberData(); + auto* results = new UFormattedNumberData(); if (results == nullptr) { status = U_MEMORY_ALLOCATION_ERROR; return FormattedNumber(status); @@ -611,7 +611,7 @@ FormattedNumber LocalizedNumberFormatter::formatDouble(double value, UErrorCode& FormattedNumber LocalizedNumberFormatter::formatDecimal(StringPiece value, UErrorCode& status) const { if (U_FAILURE(status)) { return FormattedNumber(U_ILLEGAL_ARGUMENT_ERROR); } - auto results = new UFormattedNumberData(); + auto* results = new UFormattedNumberData(); if (results == nullptr) { status = U_MEMORY_ALLOCATION_ERROR; return FormattedNumber(status); @@ -631,7 +631,7 @@ FormattedNumber LocalizedNumberFormatter::formatDecimal(StringPiece value, UErro FormattedNumber LocalizedNumberFormatter::formatDecimalQuantity(const DecimalQuantity& dq, UErrorCode& status) const { if (U_FAILURE(status)) { return FormattedNumber(U_ILLEGAL_ARGUMENT_ERROR); } - auto results = new UFormattedNumberData(); + auto* results = new UFormattedNumberData(); if (results == nullptr) { status = U_MEMORY_ALLOCATION_ERROR; return FormattedNumber(status); diff --git a/icu4c/source/i18n/number_formatimpl.cpp b/icu4c/source/i18n/number_formatimpl.cpp index 53bac49a55c..45baa94615e 100644 --- a/icu4c/source/i18n/number_formatimpl.cpp +++ b/icu4c/source/i18n/number_formatimpl.cpp @@ -229,7 +229,7 @@ NumberFormatterImpl::macrosToMicroGenerator(const MacroProps& macros, bool safe, return nullptr; } } - auto patternInfo = new ParsedPatternInfo(); + auto* patternInfo = new ParsedPatternInfo(); if (patternInfo == nullptr) { status = U_MEMORY_ALLOCATION_ERROR; return nullptr; @@ -252,12 +252,12 @@ NumberFormatterImpl::macrosToMicroGenerator(const MacroProps& macros, bool safe, status = U_ILLEGAL_ARGUMENT_ERROR; return nullptr; } - auto usagePrefsHandler = + auto* usagePrefsHandler = new UsagePrefsHandler(macros.locale, macros.unit, macros.usage.fValue, chain, status); fUsagePrefsHandler.adoptInsteadAndCheckErrorCode(usagePrefsHandler, status); chain = fUsagePrefsHandler.getAlias(); } else if (isMixedUnit) { - auto unitConversionHandler = new UnitConversionHandler(macros.unit, chain, status); + auto* unitConversionHandler = new UnitConversionHandler(macros.unit, chain, status); fUnitConversionHandler.adoptInsteadAndCheckErrorCode(unitConversionHandler, status); chain = fUnitConversionHandler.getAlias(); } @@ -333,7 +333,8 @@ NumberFormatterImpl::macrosToMicroGenerator(const MacroProps& macros, bool safe, // Inner modifier (scientific notation) if (macros.notation.fType == Notation::NTN_SCIENTIFIC) { - auto newScientificHandler = new ScientificHandler(¯os.notation, fMicros.simple.symbols, chain); + auto* newScientificHandler = + new ScientificHandler(¯os.notation, fMicros.simple.symbols, chain); if (newScientificHandler == nullptr) { status = U_MEMORY_ALLOCATION_ERROR; return nullptr; @@ -346,7 +347,7 @@ NumberFormatterImpl::macrosToMicroGenerator(const MacroProps& macros, bool safe, } // Middle modifier (patterns, positive/negative, currency symbols, percent) - auto patternModifier = new MutablePatternModifier(false); + auto* patternModifier = new MutablePatternModifier(false); if (patternModifier == nullptr) { status = U_MEMORY_ALLOCATION_ERROR; return nullptr; @@ -444,7 +445,7 @@ NumberFormatterImpl::macrosToMicroGenerator(const MacroProps& macros, bool safe, if (isCompactNotation) { CompactType compactType = (isCurrency && unitWidth != UNUM_UNIT_WIDTH_FULL_NAME) ? CompactType::TYPE_CURRENCY : CompactType::TYPE_DECIMAL; - auto newCompactHandler = new CompactHandler( + auto* newCompactHandler = new CompactHandler( macros.notation.fUnion.compactStyle, macros.locale, nsName, diff --git a/icu4c/source/i18n/number_mapper.h b/icu4c/source/i18n/number_mapper.h index 7c8cf795d5b..fc5617cb463 100644 --- a/icu4c/source/i18n/number_mapper.h +++ b/icu4c/source/i18n/number_mapper.h @@ -140,9 +140,9 @@ class AutoAffixPatternProvider { } inline void setTo(const AffixPatternProvider* provider, UErrorCode& status) { - if (auto ptr = dynamic_cast(provider)) { + if (const auto* ptr = dynamic_cast(provider)) { propertiesAPP = *ptr; - } else if (auto ptr = dynamic_cast(provider)) { + } else if (const auto* ptr = dynamic_cast(provider)) { currencyPluralInfoAPP = *ptr; } else { status = U_INTERNAL_PROGRAM_ERROR; diff --git a/icu4c/source/i18n/number_modifiers.cpp b/icu4c/source/i18n/number_modifiers.cpp index b671eadc2f8..95182382a4b 100644 --- a/icu4c/source/i18n/number_modifiers.cpp +++ b/icu4c/source/i18n/number_modifiers.cpp @@ -74,8 +74,8 @@ bool Modifier::semanticallyEquivalent(const Modifier& other) const { auto signum = static_cast(i); for (size_t j=0; j(j); - auto mod1 = paramsThis.obj->getModifier(signum, plural); - auto mod2 = paramsOther.obj->getModifier(signum, plural); + const auto* mod1 = paramsThis.obj->getModifier(signum, plural); + const auto* mod2 = paramsOther.obj->getModifier(signum, plural); if (mod1 == mod2) { // Equal pointers continue; @@ -146,7 +146,7 @@ void ConstantAffixModifier::getParameters(Parameters& output) const { } bool ConstantAffixModifier::strictEquals(const Modifier& other) const { - auto* _other = dynamic_cast(&other); + const auto* _other = dynamic_cast(&other); if (_other == nullptr) { return false; } @@ -233,7 +233,7 @@ void SimpleModifier::getParameters(Parameters& output) const { } bool SimpleModifier::strictEquals(const Modifier& other) const { - auto* _other = dynamic_cast(&other); + const auto* _other = dynamic_cast(&other); if (_other == nullptr) { return false; } @@ -360,7 +360,7 @@ void ConstantMultiFieldModifier::getParameters(Parameters& output) const { } bool ConstantMultiFieldModifier::strictEquals(const Modifier& other) const { - auto* _other = dynamic_cast(&other); + const auto* _other = dynamic_cast(&other); if (_other == nullptr) { return false; } diff --git a/icu4c/source/i18n/number_patternmodifier.cpp b/icu4c/source/i18n/number_patternmodifier.cpp index 8d9d68d628b..65476d943f7 100644 --- a/icu4c/source/i18n/number_patternmodifier.cpp +++ b/icu4c/source/i18n/number_patternmodifier.cpp @@ -85,7 +85,7 @@ ImmutablePatternModifier* MutablePatternModifier::createImmutable(UErrorCode& st StandardPlural::Form::MANY, StandardPlural::Form::OTHER}; - auto pm = new AdoptingModifierStore(); + auto* pm = new AdoptingModifierStore(); if (pm == nullptr) { status = U_MEMORY_ALLOCATION_ERROR; return nullptr; @@ -176,7 +176,7 @@ void MutablePatternModifier::processQuantity(DecimalQuantity& fq, MicroProps& mi } // The unsafe code path performs self-mutation, so we need a const_cast. // This method needs to be const because it overrides a const method in the parent class. - auto nonConstThis = const_cast(this); + auto* nonConstThis = const_cast(this); if (needsPlurals()) { StandardPlural::Form pluralForm = utils::getPluralSafe(micros.rounder, fRules, fq, status); nonConstThis->setNumberProperties(fq.signum(), pluralForm); @@ -190,7 +190,7 @@ int32_t MutablePatternModifier::apply(FormattedStringBuilder& output, int32_t le UErrorCode& status) const { // The unsafe code path performs self-mutation, so we need a const_cast. // This method needs to be const because it overrides a const method in the parent class. - auto nonConstThis = const_cast(this); + auto* nonConstThis = const_cast(this); int32_t prefixLen = nonConstThis->insertPrefix(output, leftIndex, status); int32_t suffixLen = nonConstThis->insertSuffix(output, rightIndex + prefixLen, status); // If the pattern had no decimal stem body (like #,##0.00), overwrite the value. @@ -219,7 +219,7 @@ int32_t MutablePatternModifier::apply(FormattedStringBuilder& output, int32_t le int32_t MutablePatternModifier::getPrefixLength() const { // The unsafe code path performs self-mutation, so we need a const_cast. // This method needs to be const because it overrides a const method in the parent class. - auto nonConstThis = const_cast(this); + auto* nonConstThis = const_cast(this); // Enter and exit CharSequence Mode to get the length. UErrorCode status = U_ZERO_ERROR; // status fails only with an iilegal argument exception @@ -231,7 +231,7 @@ int32_t MutablePatternModifier::getPrefixLength() const { int32_t MutablePatternModifier::getCodePointCount() const { // The unsafe code path performs self-mutation, so we need a const_cast. // This method needs to be const because it overrides a const method in the parent class. - auto nonConstThis = const_cast(this); + auto* nonConstThis = const_cast(this); // Render the affixes to get the length UErrorCode status = U_ZERO_ERROR; // status fails only with an iilegal argument exception diff --git a/icu4c/source/i18n/number_scientific.cpp b/icu4c/source/i18n/number_scientific.cpp index d45d1f34ef2..f7c5434b79c 100644 --- a/icu4c/source/i18n/number_scientific.cpp +++ b/icu4c/source/i18n/number_scientific.cpp @@ -105,7 +105,7 @@ void ScientificModifier::getParameters(Parameters& output) const { } bool ScientificModifier::strictEquals(const Modifier& other) const { - auto* _other = dynamic_cast(&other); + const auto* _other = dynamic_cast(&other); if (_other == nullptr) { return false; } diff --git a/icu4c/source/i18n/number_simple.cpp b/icu4c/source/i18n/number_simple.cpp index a2af6be42d6..060c5ff0eb9 100644 --- a/icu4c/source/i18n/number_simple.cpp +++ b/icu4c/source/i18n/number_simple.cpp @@ -22,7 +22,7 @@ SimpleNumber::forInt64(int64_t value, UErrorCode& status) { if (U_FAILURE(status)) { return SimpleNumber(); } - auto results = new UFormattedNumberData(); + auto* results = new UFormattedNumberData(); if (results == nullptr) { status = U_MEMORY_ALLOCATION_ERROR; return SimpleNumber(); @@ -176,7 +176,7 @@ void SimpleNumberFormatter::initialize( } fMicros->symbols = &symbols; - auto pattern = utils::getPatternForStyle( + const auto* pattern = utils::getPatternForStyle( locale, symbols.getNumberingSystemName(), CLDR_PATTERN_STYLE_DECIMAL, @@ -211,7 +211,7 @@ FormattedNumber SimpleNumberFormatter::format(SimpleNumber value, UErrorCode &st // Do not save the results object if we encountered a failure. if (U_SUCCESS(status)) { - auto temp = value.fData; + auto* temp = value.fData; value.fData = nullptr; return FormattedNumber(temp); } else { diff --git a/icu4c/source/i18n/number_skeletons.cpp b/icu4c/source/i18n/number_skeletons.cpp index ef3befbffad..a7173c2a84c 100644 --- a/icu4c/source/i18n/number_skeletons.cpp +++ b/icu4c/source/i18n/number_skeletons.cpp @@ -1344,7 +1344,7 @@ bool blueprint_helpers::parseFracSigOption(const StringSegment& segment, MacroPr // @, @@, @@@ maxSig = minSig; } - auto& oldPrecision = static_cast(macros.precision); + const auto& oldPrecision = static_cast(macros.precision); if (offset < segment.length()) { UNumberRoundingPriority priority; if (maxSig == -1) { diff --git a/icu4c/source/i18n/numparse_compositions.cpp b/icu4c/source/i18n/numparse_compositions.cpp index 2f7e1ab28d1..259e566d462 100644 --- a/icu4c/source/i18n/numparse_compositions.cpp +++ b/icu4c/source/i18n/numparse_compositions.cpp @@ -24,7 +24,7 @@ bool SeriesMatcher::match(StringSegment& segment, ParsedNumber& result, UErrorCo int32_t initialOffset = segment.getOffset(); bool maybeMore = true; - for (auto* it = begin(); it < end();) { + for (const auto* it = begin(); it < end();) { const NumberParseMatcher* matcher = *it; int matcherOffset = segment.getOffset(); if (segment.length() != 0) { @@ -64,7 +64,7 @@ bool SeriesMatcher::match(StringSegment& segment, ParsedNumber& result, UErrorCo bool SeriesMatcher::smokeTest(const StringSegment& segment) const { // NOTE: The range-based for loop calls the virtual begin() and end() methods. // NOTE: We only want the first element. Use the for loop for boundary checking. - for (auto& matcher : *this) { + for (const auto& matcher : *this) { // SeriesMatchers are never allowed to start with a Flexible matcher. U_ASSERT(!matcher->isFlexible()); return matcher->smokeTest(segment); @@ -74,7 +74,7 @@ bool SeriesMatcher::smokeTest(const StringSegment& segment) const { void SeriesMatcher::postProcess(ParsedNumber& result) const { // NOTE: The range-based for loop calls the virtual begin() and end() methods. - for (auto* matcher : *this) { + for (const auto* matcher : *this) { matcher->postProcess(result); } } diff --git a/icu4c/source/i18n/numparse_decimal.cpp b/icu4c/source/i18n/numparse_decimal.cpp index 8b99fd7ad4f..aedca60586a 100644 --- a/icu4c/source/i18n/numparse_decimal.cpp +++ b/icu4c/source/i18n/numparse_decimal.cpp @@ -74,7 +74,7 @@ DecimalMatcher::DecimalMatcher(const DecimalFormatSymbols& symbols, const Groupe UChar32 cpZero = symbols.getCodePointZero(); if (cpZero == -1 || !u_isdigit(cpZero) || u_digit(cpZero, 10) != 0) { // Uncommon case: okay to allocate. - auto digitStrings = new UnicodeString[10]; + auto* digitStrings = new UnicodeString[10]; fLocalDigitStrings.adoptInstead(digitStrings); for (int32_t i = 0; i <= 9; i++) { digitStrings[i] = symbols.getConstDigitSymbol(i); diff --git a/icu4c/source/i18n/numrange_capi.cpp b/icu4c/source/i18n/numrange_capi.cpp index 1432ea89ccd..ef1a29e3950 100644 --- a/icu4c/source/i18n/numrange_capi.cpp +++ b/icu4c/source/i18n/numrange_capi.cpp @@ -71,7 +71,7 @@ UPRV_FORMATTED_VALUE_CAPI_NO_IMPLTYPE_AUTO_IMPL( const UFormattedNumberRangeData* number::impl::validateUFormattedNumberRange( const UFormattedNumberRange* uresult, UErrorCode& status) { - auto* result = UFormattedNumberRangeApiHelper::validate(uresult, status); + const auto* result = UFormattedNumberRangeApiHelper::validate(uresult, status); if (U_FAILURE(status)) { return nullptr; } @@ -145,7 +145,7 @@ U_CAPI UNumberRangeIdentityResult U_EXPORT2 unumrf_resultGetIdentityResult( const UFormattedNumberRange* uresult, UErrorCode* ec) { - auto* result = UFormattedNumberRangeApiHelper::validate(uresult, *ec); + const auto* result = UFormattedNumberRangeApiHelper::validate(uresult, *ec); if (U_FAILURE(*ec)) { return UNUM_IDENTITY_RESULT_COUNT; } diff --git a/icu4c/source/i18n/numrange_fluent.cpp b/icu4c/source/i18n/numrange_fluent.cpp index c500e981ac3..e03701788ca 100644 --- a/icu4c/source/i18n/numrange_fluent.cpp +++ b/icu4c/source/i18n/numrange_fluent.cpp @@ -313,7 +313,7 @@ FormattedNumberRange LocalizedNumberRangeFormatter::formatFormattableRange( return FormattedNumberRange(U_ILLEGAL_ARGUMENT_ERROR); } - auto results = new UFormattedNumberRangeData(); + auto* results = new UFormattedNumberRangeData(); if (results == nullptr) { status = U_MEMORY_ALLOCATION_ERROR; return FormattedNumberRange(status); @@ -342,7 +342,7 @@ FormattedNumberRange LocalizedNumberRangeFormatter::formatFormattableRange( void LocalizedNumberRangeFormatter::formatImpl( UFormattedNumberRangeData& results, bool equalBeforeRounding, UErrorCode& status) const { - auto* impl = getFormatter(status); + const auto* impl = getFormatter(status); if (U_FAILURE(status)) { return; } diff --git a/icu4c/source/i18n/reldatefmt.cpp b/icu4c/source/i18n/reldatefmt.cpp index ebdf6c9716e..c3c450f376c 100644 --- a/icu4c/source/i18n/reldatefmt.cpp +++ b/icu4c/source/i18n/reldatefmt.cpp @@ -1380,7 +1380,7 @@ ureldatefmt_formatNumericToResult( if (U_FAILURE(*status)) { return; } - auto* fmt = reinterpret_cast(reldatefmt); + const auto* fmt = reinterpret_cast(reldatefmt); auto* resultImpl = UFormattedRelativeDateTimeApiHelper::validate(result, *status); resultImpl->fImpl = fmt->formatNumericToValue(offset, unit, *status); } @@ -1423,7 +1423,7 @@ ureldatefmt_formatToResult( if (U_FAILURE(*status)) { return; } - auto* fmt = reinterpret_cast(reldatefmt); + const auto* fmt = reinterpret_cast(reldatefmt); auto* resultImpl = UFormattedRelativeDateTimeApiHelper::validate(result, *status); resultImpl->fImpl = fmt->formatToValue(offset, unit, *status); } diff --git a/icu4c/source/i18n/smpdtfmt.cpp b/icu4c/source/i18n/smpdtfmt.cpp index 383c1340108..dade5a2cabc 100644 --- a/icu4c/source/i18n/smpdtfmt.cpp +++ b/icu4c/source/i18n/smpdtfmt.cpp @@ -1308,7 +1308,7 @@ SimpleDateFormat::initSimpleNumberFormatter(UErrorCode &status) { if (U_FAILURE(status)) { return; } - auto* df = dynamic_cast(fNumberFormat); + const auto* df = dynamic_cast(fNumberFormat); if (df == nullptr) { return; } @@ -1523,7 +1523,7 @@ SimpleDateFormat::subFormat(UnicodeString &appendTo, // "GGGG" is wide era name, "GGGGG" is narrow era name, anything else is abbreviated name case UDAT_ERA_FIELD: { - auto calType = cal.getType(); + const auto* calType = cal.getType(); if (uprv_strcmp(calType,"chinese") == 0 || uprv_strcmp(calType,"dangi") == 0) { zeroPaddingNumber(currentNumberFormat,appendTo, value, 1, 9); // as in ICU4J } else { @@ -2178,7 +2178,7 @@ SimpleDateFormat::zeroPaddingNumber( } // Check for RBNF (no clone necessary) - auto* rbnf = dynamic_cast(currentNumberFormat); + const auto* rbnf = dynamic_cast(currentNumberFormat); if (rbnf != nullptr) { FieldPosition pos(FieldPosition::DONT_CARE); rbnf->format(value, appendTo, pos); // 3rd arg is there to speed up processing @@ -3914,7 +3914,7 @@ void SimpleDateFormat::parseInt(const UnicodeString& text, UBool allowNegative, const NumberFormat *fmt) const { UnicodeString oldPrefix; - auto* fmtAsDF = dynamic_cast(fmt); + const auto* fmtAsDF = dynamic_cast(fmt); LocalPointer df; if (!allowNegative && fmtAsDF != nullptr) { df.adoptInstead(fmtAsDF->clone()); diff --git a/icu4c/source/i18n/units_converter.cpp b/icu4c/source/i18n/units_converter.cpp index 97707b7cf1e..e5e3b2f2dc4 100644 --- a/icu4c/source/i18n/units_converter.cpp +++ b/icu4c/source/i18n/units_converter.cpp @@ -180,7 +180,7 @@ void addFactorElement(Factor &factor, StringPiece elementStr, Signum signum, UEr Factor extractFactorConversions(StringPiece stringFactor, UErrorCode &status) { Factor result; Signum signum = Signum::POSITIVE; - auto factorData = stringFactor.data(); + const auto* factorData = stringFactor.data(); for (int32_t i = 0, start = 0, n = stringFactor.length(); i < n; i++) { if (factorData[i] == '*' || factorData[i] == '/') { StringPiece factorElement = stringFactor.substr(start, i - start); @@ -202,7 +202,7 @@ Factor extractFactorConversions(StringPiece stringFactor, UErrorCode &status) { // Load factor for a single source Factor loadSingleFactor(StringPiece source, const ConversionRates &ratesInfo, UErrorCode &status) { - const auto conversionUnit = ratesInfo.extractConversionInfo(source, status); + const auto* const conversionUnit = ratesInfo.extractConversionInfo(source, status); if (U_FAILURE(status)) return Factor(); if (conversionUnit == nullptr) { status = U_INTERNAL_PROGRAM_ERROR; @@ -280,7 +280,8 @@ CharString getSpecialMappingName(const MeasureUnitImpl &simpleUnit, const Conver return CharString(); } SingleUnitImpl singleUnit = *simpleUnit.singleUnits[0]; - const auto conversionUnit = ratesInfo.extractConversionInfo(singleUnit.getSimpleUnitID(), status); + const auto* const conversionUnit = + ratesInfo.extractConversionInfo(singleUnit.getSimpleUnitID(), status); if (U_FAILURE(status)) { return CharString(); } @@ -477,7 +478,7 @@ MeasureUnitImpl U_I18N_API extractCompoundBaseUnit(const MeasureUnitImpl &source const auto &singleUnit = *singleUnits[i]; // Extract `ConversionRateInfo` using the absolute unit. For example: in case of `square-meter`, // we will use `meter` - const auto rateInfo = + const auto* const rateInfo = conversionRates.extractConversionInfo(singleUnit.getSimpleUnitID(), status); if (U_FAILURE(status)) { return result; diff --git a/icu4c/source/i18n/units_router.cpp b/icu4c/source/i18n/units_router.cpp index 03c9b4d1d7c..0a51cda9f92 100644 --- a/icu4c/source/i18n/units_router.cpp +++ b/icu4c/source/i18n/units_router.cpp @@ -77,7 +77,7 @@ void UnitsRouter::init(const MeasureUnit &inputUnit, const Locale &locale, Strin prefs.getPreferencesFor(category.toStringPiece(), usage, locale, status); for (int32_t i = 0, n = unitPrefs.length(); i < n; ++i) { U_ASSERT(unitPrefs[i] != nullptr); - const auto preference = unitPrefs[i]; + const auto* const preference = unitPrefs[i]; MeasureUnitImpl complexTargetUnitImpl = MeasureUnitImpl::forIdentifier(preference->unit.data(), status); diff --git a/icu4c/source/i18n/uspoof_impl.cpp b/icu4c/source/i18n/uspoof_impl.cpp index 7a6084a1096..93402e670be 100644 --- a/icu4c/source/i18n/uspoof_impl.cpp +++ b/icu4c/source/i18n/uspoof_impl.cpp @@ -108,7 +108,7 @@ USpoofChecker *SpoofImpl::asUSpoofChecker() { // received from the C API. // const SpoofImpl *SpoofImpl::validateThis(const USpoofChecker *sc, UErrorCode &status) { - auto* This = validate(sc, status); + const auto* This = validate(sc, status); if (U_FAILURE(status)) { return nullptr; } diff --git a/icu4c/source/test/fuzzer/ucasemap_fuzzer.cpp b/icu4c/source/test/fuzzer/ucasemap_fuzzer.cpp index ddb03862efb..b903ca1ee49 100644 --- a/icu4c/source/test/fuzzer/ucasemap_fuzzer.cpp +++ b/icu4c/source/test/fuzzer/ucasemap_fuzzer.cpp @@ -51,7 +51,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { int32_t dst_size = size * 2; std::unique_ptr dst(new char[dst_size]); - auto src = reinterpret_cast(fuzzbuff.get()); + const auto* src = reinterpret_cast(fuzzbuff.get()); switch (rnd8 % 4) { case 0: ucasemap_utf8ToLower(csm.get(), dst.get(), dst_size, src, size, diff --git a/icu4c/source/test/intltest/dcfmapts.cpp b/icu4c/source/test/intltest/dcfmapts.cpp index 488ef79f252..18d04c5ceac 100644 --- a/icu4c/source/test/intltest/dcfmapts.cpp +++ b/icu4c/source/test/intltest/dcfmapts.cpp @@ -1191,10 +1191,10 @@ void IntlTestDecimalFormatAPI::testInvalidObject() { assertTrue(WHERE, dfAssignmentBogus != dfBogus); // Verify that cloning our original invalid object gives nullptr. - auto dfBogusClone = dfBogus.clone(); + auto* dfBogusClone = dfBogus.clone(); assertTrue(WHERE, dfBogusClone == nullptr); // Verify that cloning our assigned invalid object gives nullptr. - auto dfBogusClone2 = dfAssignmentBogus.clone(); + auto* dfBogusClone2 = dfAssignmentBogus.clone(); assertTrue(WHERE, dfBogusClone2 == nullptr); // Verify copy constructing from an invalid object is also invalid. @@ -1206,8 +1206,8 @@ void IntlTestDecimalFormatAPI::testInvalidObject() { assertTrue(WHERE, dfCopyAssign != dfGood); assertTrue(WHERE, dfCopyAssign != dfGood2); assertTrue(WHERE, dfCopyAssign != dfBogus); - auto dfBogusCopyClone1 = dfCopy.clone(); - auto dfBogusCopyClone2 = dfCopyAssign.clone(); + auto* dfBogusCopyClone1 = dfCopy.clone(); + auto* dfBogusCopyClone2 = dfCopyAssign.clone(); assertTrue(WHERE, dfBogusCopyClone1 == nullptr); assertTrue(WHERE, dfBogusCopyClone2 == nullptr); } @@ -1252,7 +1252,7 @@ void IntlTestDecimalFormatAPI::testInvalidObject() { df->setLenient(true); - auto dfClone = df->clone(); + auto* dfClone = df->clone(); assertTrue(WHERE, dfClone == nullptr); UnicodeString dest; diff --git a/icu4c/source/test/intltest/dtptngts.cpp b/icu4c/source/test/intltest/dtptngts.cpp index f780271bdec..1418b7c8d59 100644 --- a/icu4c/source/test/intltest/dtptngts.cpp +++ b/icu4c/source/test/intltest/dtptngts.cpp @@ -716,7 +716,7 @@ void IntlTestDateTimePatternGeneratorAPI::testAPI(/*char *par*/) resultDate.remove(); resultDate = sdf.format(testDate, resultDate); if ( resultDate != patternResults[localeIndex][resultIndex] ) { - auto* calendar = sdf.getCalendar(); + const auto* calendar = sdf.getCalendar(); errln(UnicodeString("\nERROR: Test various skeletons[") + (dataIndex-1) + UnicodeString("], localeIndex ") + localeIndex + u". Got: \"" + resultDate + u"\" with calendar " + calendar->getType() + @@ -1434,7 +1434,7 @@ void IntlTestDateTimePatternGeneratorAPI::test20640_HourCyclArsEnNH() { {"ja_TRADITIONAL", u"H時", u"H:mm", UDAT_HOUR_CYCLE_23}, }; - for (auto& cas : cases) { + for (const auto& cas : cases) { status.setScope(cas.localeName); Locale loc(cas.localeName); diff --git a/icu4c/source/test/intltest/itspoof.cpp b/icu4c/source/test/intltest/itspoof.cpp index e68d9b3c313..728b7e715f5 100644 --- a/icu4c/source/test/intltest/itspoof.cpp +++ b/icu4c/source/test/intltest/itspoof.cpp @@ -838,7 +838,7 @@ void IntlTestSpoof::testCombiningDot() { {false, u"iz\u0307"}, }; - for (auto& cas : cases) { + for (const auto& cas : cases) { int32_t failedChecks = uspoof_check2(sc.getAlias(), cas.input, -1, nullptr, &status); TEST_ASSERT_SUCCESS(status); int32_t expected = cas.shouldFail ? USPOOF_HIDDEN_OVERLAY : 0; diff --git a/icu4c/source/test/intltest/loctest.cpp b/icu4c/source/test/intltest/loctest.cpp index 50aafd39b60..f12b954ab00 100644 --- a/icu4c/source/test/intltest/loctest.cpp +++ b/icu4c/source/test/intltest/loctest.cpp @@ -1685,7 +1685,7 @@ void LocaleTest::Test20639_DeprecatesISO3Language() { {"ro", "ron"}, {"mo", "mol"}, }; - for (auto& cas : cases) { + for (const auto& cas : cases) { Locale loc(cas.localeName); const char* actual = loc.getISO3Language(); assertEquals(cas.localeName, cas.expectedISO3Language, actual); diff --git a/icu4c/source/test/intltest/measfmttest.cpp b/icu4c/source/test/intltest/measfmttest.cpp index de6f82f745c..5daa4cdeab3 100644 --- a/icu4c/source/test/intltest/measfmttest.cpp +++ b/icu4c/source/test/intltest/measfmttest.cpp @@ -5836,7 +5836,7 @@ void MeasureFormatTest::TestParseToBuiltIn() { {"square-yard-yard", MeasureUnit::getCubicYard()}, }; - for (auto &cas : cases) { + for (const auto& cas : cases) { MeasureUnit fromIdent = MeasureUnit::forIdentifier(cas.identifier, status); status.assertSuccess(); assertEquals("forIdentifier returns a normal built-in unit when it exists", diff --git a/icu4c/source/test/intltest/numbertest_api.cpp b/icu4c/source/test/intltest/numbertest_api.cpp index e764ee654cd..f9072eb549c 100644 --- a/icu4c/source/test/intltest/numbertest_api.cpp +++ b/icu4c/source/test/intltest/numbertest_api.cpp @@ -1346,7 +1346,7 @@ void NumberFormatterApiTest::unitSkeletons() { u"unit/kibijoule-per-furlong", // u"unit/kibijoule-per-furlong"}, }; - for (auto &cas : cases) { + for (const auto& cas : cases) { IcuTestErrorCode status(*this, cas.msg); auto nf = NumberFormatter::forSkeleton(cas.inputSkeleton, status); if (status.errIfFailureAndReset("NumberFormatter::forSkeleton failed")) { @@ -1390,7 +1390,7 @@ void NumberFormatterApiTest::unitSkeletons() { U_NUMBER_SKELETON_SYNTAX_ERROR, // U_ZERO_ERROR}, }; - for (auto &cas : failCases) { + for (const auto& cas : failCases) { IcuTestErrorCode status(*this, cas.msg); auto nf = NumberFormatter::forSkeleton(cas.inputSkeleton, status); if (status.expectErrorAndReset(cas.expectedForSkelStatus, cas.msg)) { @@ -3019,7 +3019,7 @@ void NumberFormatterApiTest::unitLocaleTags() { Locale locale(testCase.locale); auto inputUnit = MeasureUnit::forIdentifier(testCase.inputUnit, status); auto inputValue = testCase.inputValue; - auto usage = testCase.usage; + const auto* usage = testCase.usage; auto expectedOutputUnit = MeasureUnit::forIdentifier(testCase.expectedOutputUnit, status); UnicodeString expectedFormattedNumber = testCase.expectedFormattedNumber; @@ -3050,9 +3050,9 @@ void NumberFormatterApiTest::percentParity() { UnlocalizedNumberFormatter uMeasurePermille = NumberFormatter::with().unit(MeasureUnit::getPermille()); int32_t localeCount; - auto locales = Locale::getAvailableLocales(localeCount); + const auto* locales = Locale::getAvailableLocales(localeCount); for (int32_t i=0; i parser( @@ -227,7 +227,7 @@ void NumberParserTest::testSeriesMatcher() { {u"+- % ", 7, true}, {u"+-%$", 3, false}}; - for (auto& cas : cases) { + for (const auto& cas : cases) { UnicodeString input(cas.input); StringSegment segment(input, false); @@ -275,7 +275,7 @@ void NumberParserTest::testCombinedCurrencyMatcher() { {u"euros", u"EUR", u""}, {u"ICU", u"ICU", u"ICU"}, {u"IU$", u"ICU", u"ICU"}}; - for (auto& cas : cases) { + for (const auto& cas : cases) { UnicodeString input(cas.input); { @@ -333,7 +333,7 @@ void NumberParserTest::testAffixPatternMatcher() { {true, u"abc", 3, u"abc"}, {false, u"hello-to+this%very¤long‰string", 59, u"hello-to+this%very USD long‰string"}}; - for (auto& cas : cases) { + for (const auto& cas : cases) { UnicodeString affixPattern(cas.affixPattern); UnicodeString sampleParseableString(cas.sampleParseableString); int parseFlags = cas.exactMatch ? PARSE_FLAG_EXACT_AFFIX : 0; diff --git a/icu4c/source/test/intltest/numbertest_patternstring.cpp b/icu4c/source/test/intltest/numbertest_patternstring.cpp index 0bfd58016ff..f3ea770158b 100644 --- a/icu4c/source/test/intltest/numbertest_patternstring.cpp +++ b/icu4c/source/test/intltest/numbertest_patternstring.cpp @@ -100,7 +100,7 @@ void PatternStringTest::testExceptionOnInvalid() { u"0,,0,", u"#,##0E0"}; - for (auto pattern : invalidPatterns) { + for (const auto* pattern : invalidPatterns) { UErrorCode status = U_ZERO_ERROR; ParsedPatternInfo patternInfo; PatternParser::parseToPatternInfo(pattern, patternInfo, status); diff --git a/icu4c/source/test/intltest/numbertest_range.cpp b/icu4c/source/test/intltest/numbertest_range.cpp index a337e8d8a2d..61263d7acd1 100644 --- a/icu4c/source/test/intltest/numbertest_range.cpp +++ b/icu4c/source/test/intltest/numbertest_range.cpp @@ -1128,7 +1128,7 @@ void NumberRangeFormatterTest::test21683_StateLeak() { unumrf_formatDoubleRange(nrf, range.start, range.end, result, status); if (status.errIfFailureAndReset("unumrf_formatDoubleRange")) { goto cleanup; } - auto* formattedValue = unumrf_resultAsValue(result, status); + const auto* formattedValue = unumrf_resultAsValue(result, status); if (status.errIfFailureAndReset("unumrf_resultAsValue")) { goto cleanup; } int32_t utf16Length; diff --git a/icu4c/source/test/intltest/numfmtst.cpp b/icu4c/source/test/intltest/numfmtst.cpp index 357f6076870..109d36e5dd6 100644 --- a/icu4c/source/test/intltest/numfmtst.cpp +++ b/icu4c/source/test/intltest/numfmtst.cpp @@ -9909,7 +9909,7 @@ void NumberFormatTest::Test21134_ToNumberFormatter() { { // Case 1: new formatter object DecimalFormat inner(u"a0b", {"en", status}, status); - if (auto ptr = inner.toNumberFormatter(status)) { + if (const auto* ptr = inner.toNumberFormatter(status)) { // Copy assignment outer1 = *ptr; } else { @@ -9924,7 +9924,7 @@ void NumberFormatTest::Test21134_ToNumberFormatter() { inner.format(100, dummy); inner.format(100, dummy); inner.format(100, dummy); - if (auto ptr = inner.toNumberFormatter(status)) { + if (const auto* ptr = inner.toNumberFormatter(status)) { // Copy assignment outer2 = *ptr; } else { @@ -9936,7 +9936,7 @@ void NumberFormatTest::Test21134_ToNumberFormatter() { // Case 3: currency plural info (different code path) LocalPointer inner(dynamic_cast( DecimalFormat::createInstance("en-US", UNUM_CURRENCY_PLURAL, status))); - if (auto ptr = inner->toNumberFormatter(status)) { + if (const auto* ptr = inner->toNumberFormatter(status)) { // Copy constructor outer3.adoptInsteadAndCheckErrorCode(new LocalizedNumberFormatter(*ptr), status); } else { @@ -10009,7 +10009,7 @@ void NumberFormatTest::Test13733_StrictAndLenient() { {u"12$", u"0 ¤¤", 0, 12}, {u"12$", u"0 ¤¤¤", 0, 12}, {u"12$", u"¤¤¤¤0", 0, 12} }; - for (auto& cas : cases) { + for (const auto& cas : cases) { UnicodeString inputString(cas.inputString); UnicodeString patternString(cas.patternString); int64_t parsedStrictValue = 0; diff --git a/icu4c/source/test/intltest/tmsgfmt.cpp b/icu4c/source/test/intltest/tmsgfmt.cpp index 31f90a58392..ad676d1c29d 100644 --- a/icu4c/source/test/intltest/tmsgfmt.cpp +++ b/icu4c/source/test/intltest/tmsgfmt.cpp @@ -2019,7 +2019,7 @@ void TestMessageFormat::TestMessageFormatNumberSkeleton() { { u"{0,number,'::'0.00}", "en", 50, u"::50.00" }, // pattern literal }; - for (auto& cas : cases) { + for (const auto& cas : cases) { status.setScope(cas.messagePattern); MessageFormat msgf(cas.messagePattern, cas.localeName, status); UnicodeString sb; diff --git a/icu4c/source/test/intltest/units_data_test.cpp b/icu4c/source/test/intltest/units_data_test.cpp index 40d6d65e808..8489c100b32 100644 --- a/icu4c/source/test/intltest/units_data_test.cpp +++ b/icu4c/source/test/intltest/units_data_test.cpp @@ -134,8 +134,8 @@ void UnitsDataTest::testGetPreferencesFor() { }; IcuTestErrorCode status(*this, "testGetPreferencesFor"); UnitPreferencesOpenedUp preferences(status); - auto *metadata = preferences.getInternalMetadata(); - auto *unitPrefs = preferences.getInternalUnitPrefs(); + const auto* metadata = preferences.getInternalMetadata(); + const auto* unitPrefs = preferences.getInternalUnitPrefs(); assertTrue(UnicodeString("Metadata count: ") + metadata->length() + " > 200", metadata->length() > 200); assertTrue(UnicodeString("Preferences count: ") + unitPrefs->length() + " > 250", diff --git a/icu4c/source/tools/genrb/filterrb.cpp b/icu4c/source/tools/genrb/filterrb.cpp index d6480968742..494aedce778 100644 --- a/icu4c/source/tools/genrb/filterrb.cpp +++ b/icu4c/source/tools/genrb/filterrb.cpp @@ -60,7 +60,7 @@ const std::list& ResKeyPath::pieces() const { std::ostream& operator<<(std::ostream& out, const ResKeyPath& value) { if (value.pieces().empty()) { out << "/"; - } else for (auto& key : value.pieces()) { + } else for (const auto& key : value.pieces()) { out << "/" << key; } return out; @@ -109,7 +109,7 @@ PathFilter::EInclusion SimpleRuleBasedPathFilter::match(const ResKeyPath& path) // even if additional subpaths are added to the given key bool isLeaf = false; - for (auto& key : path.pieces()) { + for (const auto& key : path.pieces()) { auto child = node->fChildren.find(key); // Leaf case 1: input path descends outside the filter tree if (child == node->fChildren.end()) { @@ -178,7 +178,7 @@ void SimpleRuleBasedPathFilter::Tree::applyRule( } // Recursive Step - auto& key = *it; + const auto& key = *it; if (key == "*") { // Case 1: Wildcard if (!fWildcard) { @@ -212,7 +212,7 @@ void SimpleRuleBasedPathFilter::Tree::applyRule( void SimpleRuleBasedPathFilter::Tree::print(std::ostream& out, int32_t indent) const { for (int32_t i=0; i