diff --git a/.ci-builds/.azure-pipelines.yml b/.ci-builds/.azure-pipelines.yml index 872a052364a..c6f011495c2 100644 --- a/.ci-builds/.azure-pipelines.yml +++ b/.ci-builds/.azure-pipelines.yml @@ -118,6 +118,24 @@ jobs: CC: gcc CXX: g++ #------------------------------------------------------------------------- +- job: ICU4C_Clang_Ubuntu_2004_LANG + displayName: 'C: Linux Clang (Ubuntu 20.04) - LANG has extension tags' + timeoutInMinutes: 30 + pool: + vmImage: 'ubuntu-20.04' + steps: + - checkout: self + lfs: true + fetchDepth: 10 + - script: | + cd icu4c/source && ./runConfigureICU Linux && make -j2 check + displayName: 'Build and Test' + env: + CC: clang + CXX: clang++ + LANG: "en_US@calendar=gregorian;hours=h12" + +#------------------------------------------------------------------------- # VS 2019 Builds #------------------------------------------------------------------------- - job: ICU4C_MSVC_x64_Release_Distrelease diff --git a/icu4c/source/common/localebuilder.cpp b/icu4c/source/common/localebuilder.cpp index 1dd8131e589..a5f201e8475 100644 --- a/icu4c/source/common/localebuilder.cpp +++ b/icu4c/source/common/localebuilder.cpp @@ -228,7 +228,7 @@ LocaleBuilder& LocaleBuilder::setExtension(char key, StringPiece value) return *this; } if (extensions_ == nullptr) { - extensions_ = new Locale(); + extensions_ = Locale::getRoot().clone(); if (extensions_ == nullptr) { status_ = U_MEMORY_ALLOCATION_ERROR; return *this; @@ -259,11 +259,11 @@ LocaleBuilder& LocaleBuilder::setUnicodeLocaleKeyword( return *this; } if (extensions_ == nullptr) { - extensions_ = new Locale(); - } - if (extensions_ == nullptr) { - status_ = U_MEMORY_ALLOCATION_ERROR; - return *this; + extensions_ = Locale::getRoot().clone(); + if (extensions_ == nullptr) { + status_ = U_MEMORY_ALLOCATION_ERROR; + return *this; + } } extensions_->setUnicodeKeywordValue(key, type, status_); return *this; @@ -280,7 +280,7 @@ LocaleBuilder& LocaleBuilder::addUnicodeLocaleAttribute( return *this; } if (extensions_ == nullptr) { - extensions_ = new Locale(); + extensions_ = Locale::getRoot().clone(); if (extensions_ == nullptr) { status_ = U_MEMORY_ALLOCATION_ERROR; return *this; @@ -415,7 +415,7 @@ void LocaleBuilder::copyExtensionsFrom(const Locale& src, UErrorCode& errorCode) return; } if (extensions_ == nullptr) { - extensions_ = new Locale(); + extensions_ = Locale::getRoot().clone(); if (extensions_ == nullptr) { status_ = U_MEMORY_ALLOCATION_ERROR; return; diff --git a/icu4c/source/test/intltest/localebuildertest.cpp b/icu4c/source/test/intltest/localebuildertest.cpp index 70271211ab0..7cade3650c1 100644 --- a/icu4c/source/test/intltest/localebuildertest.cpp +++ b/icu4c/source/test/intltest/localebuildertest.cpp @@ -25,6 +25,7 @@ void LocaleBuilderTest::runIndexedTest( int32_t index, UBool exec, const char* & TESTCASE_AUTO(TestAddUnicodeLocaleAttributeIllFormed); TESTCASE_AUTO(TestLocaleBuilder); TESTCASE_AUTO(TestLocaleBuilderBasic); + TESTCASE_AUTO(TestLocaleBuilderBasicWithExtensionsOnDefaultLocale); TESTCASE_AUTO(TestPosixCases); TESTCASE_AUTO(TestSetExtensionOthers); TESTCASE_AUTO(TestSetExtensionPU); @@ -363,6 +364,25 @@ void LocaleBuilderTest::TestLocaleBuilderBasic() { "setRegion('') got Error: %s\n"); } +void LocaleBuilderTest::TestLocaleBuilderBasicWithExtensionsOnDefaultLocale() { + // Change the default locale to one with extension tags. + UErrorCode status = U_ZERO_ERROR; + Locale originalDefault; + Locale::setDefault(Locale::createFromName("en-US-u-hc-h12"), status); + if (U_FAILURE(status)) { + errln("ERROR: Could not change the default locale"); + return; + } + + // Invoke the basic test now that the default locale has been changed. + TestLocaleBuilderBasic(); + + Locale::setDefault(originalDefault, status); + if (U_FAILURE(status)) { + errln("ERROR: Could not restore the default locale"); + } +} + void LocaleBuilderTest::TestSetLanguageWellFormed() { // http://www.unicode.org/reports/tr35/tr35.html#unicode_language_subtag // unicode_language_subtag = alpha{2,3} | alpha{5,8}; diff --git a/icu4c/source/test/intltest/localebuildertest.h b/icu4c/source/test/intltest/localebuildertest.h index 41f3730ff24..f2c9658044a 100644 --- a/icu4c/source/test/intltest/localebuildertest.h +++ b/icu4c/source/test/intltest/localebuildertest.h @@ -20,6 +20,7 @@ class LocaleBuilderTest: public IntlTest { void TestAddUnicodeLocaleAttributeIllFormed(void); void TestLocaleBuilder(void); void TestLocaleBuilderBasic(void); + void TestLocaleBuilderBasicWithExtensionsOnDefaultLocale(void); void TestPosixCases(void); void TestSetExtensionOthers(void); void TestSetExtensionPU(void);