ICU-22621 Clang-Tidy: modernize-return-braced-init-list

https://releases.llvm.org/17.0.1/tools/clang/tools/extra/docs/clang-tidy/checks/modernize/return-braced-init-list.html
This commit is contained in:
Fredrik Roubert 2024-03-21 11:46:25 +00:00 committed by Fredrik Roubert
parent 80a01a475b
commit 91721504ef
22 changed files with 49 additions and 49 deletions

View file

@ -497,7 +497,7 @@ BreakIterator::makeInstance(const Locale& loc, int32_t kind, UErrorCode& status)
Locale
BreakIterator::getLocale(ULocDataLocaleType type, UErrorCode& status) const {
if (type == ULOC_REQUESTED_LOCALE) {
return Locale(requestLocale);
return {requestLocale};
}
U_LOCALE_BASED(locBased, *this);
return locBased.getLocale(type, status);

View file

@ -571,7 +571,7 @@ const uint8_t *ResourceDataValue::getBinary(int32_t &length, UErrorCode &errorCo
ResourceArray ResourceDataValue::getArray(UErrorCode &errorCode) const {
if(U_FAILURE(errorCode)) {
return ResourceArray();
return {};
}
const uint16_t *items16 = nullptr;
const Resource *items32 = nullptr;
@ -590,14 +590,14 @@ ResourceArray ResourceDataValue::getArray(UErrorCode &errorCode) const {
break;
default:
errorCode = U_RESOURCE_TYPE_MISMATCH;
return ResourceArray();
return {};
}
return ResourceArray(items16, items32, length, fTraceInfo);
}
ResourceTable ResourceDataValue::getTable(UErrorCode &errorCode) const {
if(U_FAILURE(errorCode)) {
return ResourceTable();
return {};
}
const uint16_t *keys16 = nullptr;
const int32_t *keys32 = nullptr;
@ -627,7 +627,7 @@ ResourceTable ResourceDataValue::getTable(UErrorCode &errorCode) const {
break;
default:
errorCode = U_RESOURCE_TYPE_MISMATCH;
return ResourceTable();
return {};
}
return ResourceTable(keys16, keys32, items16, items32, length, fTraceInfo);
}

View file

@ -808,7 +808,7 @@ UnicodeString CalendarAstronomer::Ecliptic::toString() const
snprintf(tmp, sizeof(tmp), "[%.5f,%.5f]", longitude*RAD_DEG, latitude*RAD_DEG);
return UnicodeString(tmp, "");
#else
return UnicodeString();
return {};
#endif
}
@ -820,10 +820,11 @@ UnicodeString CalendarAstronomer::Equatorial::toString() const
(ascension*RAD_DEG), (declination*RAD_DEG));
return UnicodeString(tmp, "");
#else
return UnicodeString();
return {};
#endif
}
// =============== Calendar Cache ================
void CalendarCache::createCache(CalendarCache** cache, UErrorCode& status) {

View file

@ -452,13 +452,13 @@ DateFormat::getBestPattern(
UErrorCode &status) {
UnifiedCache *cache = UnifiedCache::getInstance(status);
if (U_FAILURE(status)) {
return UnicodeString();
return {};
}
DateFmtBestPatternKey key(locale, skeleton, status);
const DateFmtBestPattern *patternPtr = nullptr;
cache->get(key, patternPtr, status);
if (U_FAILURE(status)) {
return UnicodeString();
return {};
}
UnicodeString result(patternPtr->fPattern);
patternPtr->removeRef();

View file

@ -11,7 +11,7 @@
U_NAMESPACE_BEGIN
DisplayOptions::Builder DisplayOptions::builder() { return DisplayOptions::Builder(); }
DisplayOptions::Builder DisplayOptions::builder() { return {}; }
DisplayOptions::Builder DisplayOptions::copyToBuilder() const { return Builder(*this); }

View file

@ -1149,11 +1149,11 @@ DateTimePatternGenerator::getBestPattern(const UnicodeString& patternForm, UErro
UnicodeString
DateTimePatternGenerator::getBestPattern(const UnicodeString& patternForm, UDateTimePatternMatchOptions options, UErrorCode& status) {
if (U_FAILURE(status)) {
return UnicodeString();
return {};
}
if (U_FAILURE(internalErrorCode)) {
status = internalErrorCode;
return UnicodeString();
return {};
}
const UnicodeString *bestPattern = nullptr;
UnicodeString dtFormat;
@ -1166,7 +1166,7 @@ DateTimePatternGenerator::getBestPattern(const UnicodeString& patternForm, UDate
// Replace hour metacharacters 'j', 'C' and 'J', set flags as necessary
UnicodeString patternFormMapped = mapSkeletonMetacharacters(patternForm, &flags, status);
if (U_FAILURE(status)) {
return UnicodeString();
return {};
}
resultPattern.remove();
@ -1174,7 +1174,7 @@ DateTimePatternGenerator::getBestPattern(const UnicodeString& patternForm, UDate
const PtnSkeleton* specifiedSkeleton = nullptr;
bestPattern=getBestRaw(*dtMatcher, -1, distanceInfo, status, &specifiedSkeleton);
if (U_FAILURE(status)) {
return UnicodeString();
return {};
}
if ( distanceInfo->missingFieldMask==0 && distanceInfo->extraFieldMask==0 ) {
@ -1186,7 +1186,7 @@ DateTimePatternGenerator::getBestPattern(const UnicodeString& patternForm, UDate
UnicodeString datePattern=getBestAppending(neededFields & dateMask, flags, status, options);
UnicodeString timePattern=getBestAppending(neededFields & timeMask, flags, status, options);
if (U_FAILURE(status)) {
return UnicodeString();
return {};
}
if (datePattern.length()==0) {
if (timePattern.length()==0) {
@ -1262,7 +1262,7 @@ DateTimePatternGenerator::mapSkeletonMetacharacters(const UnicodeString& pattern
bestAllowed = (AllowedHourFormat)fAllowedHourFormats[0];
} else {
status = U_INVALID_FORMAT_ERROR;
return UnicodeString();
return {};
}
if (bestAllowed == ALLOWED_HOUR_FORMAT_H || bestAllowed == ALLOWED_HOUR_FORMAT_HB || bestAllowed == ALLOWED_HOUR_FORMAT_Hb) {
hourChar = CAP_H;
@ -1313,11 +1313,11 @@ DateTimePatternGenerator::replaceFieldTypes(const UnicodeString& pattern,
UDateTimePatternMatchOptions options,
UErrorCode& status) {
if (U_FAILURE(status)) {
return UnicodeString();
return {};
}
if (U_FAILURE(internalErrorCode)) {
status = internalErrorCode;
return UnicodeString();
return {};
}
dtMatcher->set(skeleton, fp);
UnicodeString result = adjustFieldTypes(pattern, nullptr, kDTPGNoFlags, options);
@ -1770,7 +1770,7 @@ DateTimePatternGenerator::adjustFieldTypes(const UnicodeString& pattern,
UnicodeString
DateTimePatternGenerator::getBestAppending(int32_t missingFields, int32_t flags, UErrorCode &status, UDateTimePatternMatchOptions options) {
if (U_FAILURE(status)) {
return UnicodeString();
return {};
}
UnicodeString resultPattern, tempPattern;
const UnicodeString* tempPatternPtr;
@ -1780,7 +1780,7 @@ DateTimePatternGenerator::getBestAppending(int32_t missingFields, int32_t flags,
const PtnSkeleton* specifiedSkeleton=nullptr;
tempPatternPtr = getBestRaw(*dtMatcher, missingFields, distanceInfo, status, &specifiedSkeleton);
if (U_FAILURE(status)) {
return UnicodeString();
return {};
}
tempPattern = *tempPatternPtr;
resultPattern = adjustFieldTypes(tempPattern, specifiedSkeleton, flags, options);
@ -1800,7 +1800,7 @@ DateTimePatternGenerator::getBestAppending(int32_t missingFields, int32_t flags,
int32_t startingMask = distanceInfo->missingFieldMask;
tempPatternPtr = getBestRaw(*dtMatcher, distanceInfo->missingFieldMask, distanceInfo, status, &specifiedSkeleton);
if (U_FAILURE(status)) {
return UnicodeString();
return {};
}
tempPattern = *tempPatternPtr;
tempPattern = adjustFieldTypes(tempPattern, specifiedSkeleton, flags, options);

View file

@ -546,13 +546,13 @@ public:
*/
static Parser from(StringPiece source, UErrorCode& status) {
if (U_FAILURE(status)) {
return Parser();
return {};
}
umtx_initOnce(gUnitExtrasInitOnce, &initUnitExtras, status);
if (U_FAILURE(status)) {
return Parser();
return {};
}
return Parser(source);
return {source};
}
MeasureUnitImpl parse(UErrorCode& status) {
@ -663,7 +663,7 @@ private:
} else {
fIndex = previ;
}
return Token(match);
return {match};
}
/**

View file

@ -126,7 +126,7 @@ icu::number::impl::resolveCurrency(const DecimalFormatProperties& properties, co
return CurrencyUnit(buf, status);
} else {
// Default currency (XXX)
return CurrencyUnit();
return {};
}
}
}

View file

@ -498,7 +498,7 @@ CurrencySpacingEnabledModifier::getUnicodeSet(const DecimalFormatSymbols &symbol
// Ensure the static defaults are initialized:
umtx_initOnce(gDefaultCurrencySpacingInitOnce, &initDefaultCurrencySpacing, status);
if (U_FAILURE(status)) {
return UnicodeSet();
return {};
}
const UnicodeString& pattern = symbols.getPatternForCurrencySpacing(

View file

@ -334,7 +334,7 @@ UnicodeString MutablePatternModifier::getCurrencySymbolForUnitWidth(UErrorCode&
case UNumberUnitWidth::UNUM_UNIT_WIDTH_VARIANT:
return fCurrencySymbols.getVariantCurrencySymbol(status);
case UNumberUnitWidth::UNUM_UNIT_WIDTH_HIDDEN:
return UnicodeString();
return {};
default:
return fCurrencySymbols.getCurrencySymbol(status);
}

View file

@ -66,7 +66,7 @@ int32_t ParsedPatternInfo::getLengthFromEndpoints(const Endpoints& endpoints) {
UnicodeString ParsedPatternInfo::getString(int32_t flags) const {
const Endpoints& endpoints = getEndpoints(flags);
if (endpoints.start == endpoints.end) {
return UnicodeString();
return {};
}
// Create a new UnicodeString
return UnicodeString(pattern, endpoints.start, endpoints.end - endpoints.start);

View file

@ -20,12 +20,12 @@ using namespace icu::number::impl;
SimpleNumber
SimpleNumber::forInt64(int64_t value, UErrorCode& status) {
if (U_FAILURE(status)) {
return SimpleNumber();
return {};
}
auto* results = new UFormattedNumberData();
if (results == nullptr) {
status = U_MEMORY_ALLOCATION_ERROR;
return SimpleNumber();
return {};
}
results->quantity.setToLong(value);
return SimpleNumber(results, status);

View file

@ -184,7 +184,7 @@ Notation stem_to_object::notation(skeleton::StemEnum stem) {
MeasureUnit stem_to_object::unit(skeleton::StemEnum stem) {
switch (stem) {
case STEM_BASE_UNIT:
return MeasureUnit();
return {};
case STEM_PERCENT:
return MeasureUnit::getPercent();
case STEM_PERMILLE:

View file

@ -1037,7 +1037,7 @@ RuleBasedNumberFormat::getNumberOfRuleSetDisplayNameLocales() const {
Locale
RuleBasedNumberFormat::getRuleSetDisplayNameLocale(int32_t index, UErrorCode& status) const {
if (U_FAILURE(status)) {
return Locale("");
return {""};
}
if (localizations && index >= 0 && index < localizations->getNumberOfDisplayLocales()) {
UnicodeString name(true, localizations->getLocaleName(index), -1);
@ -1048,7 +1048,7 @@ RuleBasedNumberFormat::getRuleSetDisplayNameLocale(int32_t index, UErrorCode& st
bp = (char *)uprv_malloc(cap);
if (bp == nullptr) {
status = U_MEMORY_ALLOCATION_ERROR;
return Locale("");
return {""};
}
}
name.extract(0, name.length(), bp, cap, UnicodeString::kInvariant);

View file

@ -577,7 +577,7 @@ UnicodeString RegexPattern::pattern() const {
if (fPatternString != nullptr) {
return *fPatternString;
} else if (fPattern == nullptr) {
return UnicodeString();
return {};
} else {
UErrorCode status = U_ZERO_ERROR;
int64_t nativeLen = utext_nativeLength(fPattern);

View file

@ -43,7 +43,7 @@ namespace NoUnit {
* @stable ICU 68
*/
static inline MeasureUnit U_EXPORT2 base() {
return MeasureUnit();
return {};
}
/**

View file

@ -203,10 +203,10 @@ Factor extractFactorConversions(StringPiece stringFactor, UErrorCode &status) {
// Load factor for a single source
Factor loadSingleFactor(StringPiece source, const ConversionRates &ratesInfo, UErrorCode &status) {
const auto* const conversionUnit = ratesInfo.extractConversionInfo(source, status);
if (U_FAILURE(status)) return Factor();
if (U_FAILURE(status)) return {};
if (conversionUnit == nullptr) {
status = U_INTERNAL_PROGRAM_ERROR;
return Factor();
return {};
}
Factor result = extractFactorConversions(conversionUnit->factor.toStringPiece(), status);
@ -277,17 +277,17 @@ UBool checkSimpleUnit(const MeasureUnitImpl &unit, UErrorCode &status) {
CharString getSpecialMappingName(const MeasureUnitImpl &simpleUnit, const ConversionRates &ratesInfo,
UErrorCode &status) {
if (!checkSimpleUnit(simpleUnit, status)) {
return CharString();
return {};
}
SingleUnitImpl singleUnit = *simpleUnit.singleUnits[0];
const auto* const conversionUnit =
ratesInfo.extractConversionInfo(singleUnit.getSimpleUnitID(), status);
if (U_FAILURE(status)) {
return CharString();
return {};
}
if (conversionUnit == nullptr) {
status = U_INTERNAL_PROGRAM_ERROR;
return CharString();
return {};
}
CharString result;
result.copyFrom(conversionUnit->specialMappingName, status);

View file

@ -54,7 +54,7 @@ UnicodeString select(const PluralRules &rules, const Formattable& obj, const Num
}
}
}
return UnicodeString();
return {};
}
} // namespace

View file

@ -47,7 +47,7 @@ UnicodeString FieldsSet::diffFrom(const FieldsSet& other, UErrorCode& status) co
UnicodeString str;
if(!isSameType(other)) {
status = U_ILLEGAL_ARGUMENT_ERROR;
return UnicodeString("U_ILLEGAL_ARGUMENT_ERROR: FieldsSet of a different type!");
return {"U_ILLEGAL_ARGUMENT_ERROR: FieldsSet of a different type!"};
}
for (int i=0; i<fieldCount(); i++) {
if (isSet((UCalendarDateFields)i)) {

View file

@ -67,8 +67,7 @@ static UBool noKnownIssues = false; // if true, don't emit known issues
// [LIU] Just to get things working
UnicodeString
UCharToUnicodeString(char16_t c)
{ return UnicodeString(c); }
UCharToUnicodeString(char16_t c) { return {c}; }
// [rtg] Just to get things working
UnicodeString

View file

@ -4912,9 +4912,9 @@ static Locale _canonicalize(int32_t selector, /* 0==createFromName, 1==createCan
case 1:
return Locale::createCanonical(localeID);
case 2:
return Locale(localeID);
return {localeID};
default:
return Locale("");
return {""};
}
}

View file

@ -1408,7 +1408,7 @@ UnicodeString TestIDNA::testCompareReferenceImpl(UnicodeString& src,
+ " Got: " + UnicodeString(u_errorName(gotStatus))
+ " for Source: "+ prettify(srcUChars)
+ " Options: " + options);
return UnicodeString("");
return {""};
}
// now we know that both implementations yielded same error
@ -1430,7 +1430,7 @@ UnicodeString TestIDNA::testCompareReferenceImpl(UnicodeString& src,
+ " with "+ UnicodeString(uIDNAName)
+" for input: " + prettify(srcUChars));
}
return UnicodeString("");
return {""};
}
void TestIDNA::testCompareReferenceImpl(const char16_t* src, int32_t srcLen){