Hello ICU Team,
The new templated operator+ overload introduced in ICU 76.1 causes compilation errors on Windows when concatenating std::wstring with wide character arrays.
Issue:
The templated operator+ in unicode/unistr.h:
template<typename S, typename = std::enable_if_t<ConvertibleToU16StringView<S>>>
inline UnicodeString operator+(const UnicodeString &s1, const S &s2)
creates ambiguity with std::operator+ because on Windows (where sizeof(wchar_t) == 2), the template matches wchar_t[N] arrays through the ConvertibleToU16StringView trait.
Minimal Reproducer:
#include <string>
#include <unicode/unistr.h>
int main() {
std::wstring path = L"C:\\temp";
wchar_t filename[260] = L"test.txt";
// SCENARIO 1: WORKS - Using operator+=
std::wstring result1 = path + L"\\";
result1 += filename;
// SCENARIO 2: FAILS - Using operator+
std::wstring result2 = path + L"\\" + filename;
return 0;
}
Compilation Error (MSVC):
error C2666: 'operator+': overloaded functions have similar conversions
- std::operator+(std::wstring, const wchar_t*)
- icu::operator+(const UnicodeString&, const wchar_t(&)[260])
Impact:
This breaks existing code, including Boost.Interprocess (boost/interprocess/detail/os_file_functions.hpp:380) where similar string concatenation patterns are used:
strFilePath = refcstrRootDirectory + backslash + FileInformation.cFileName;
This overload has been moved out of the DRAFT API in the latest ICU release. Could you please advise on the recommended way to proceed for affected projects?
Should we expect a further update or workaround, or is there a migration path you would suggest?
Thank you for your consideration and guidance.
Best regards,
Vaishnav
Compilation Error (MSVC):
error C2666: 'operator+': overloaded functions have similar conversions
- std::operator+(std::wstring, const wchar_t*)
- icu::operator+(const UnicodeString&, const wchar_t(&)[260])
Impact:
This breaks existing code, including Boost.Interprocess (boost/interprocess/detail/os_file_functions.hpp:380) where similar string concatenation patterns are used:
strFilePath = refcstrRootDirectory + backslash + FileInformation.cFileName;
Could you please create a Jira ticket?
Le mar. 16 déc. 2025 à 20:07, Markus Scherer <marku...@gmail.com> a écrit :Could you please create a Jira ticket?I don’t think Vaishnav got to that yet, so I filed https://unicode-org.atlassian.net/browse/ICU-23299.Fixing in https://github.com/unicode-org/icu/pull/3809.