RESOLVED DUPLICATE of bug 299689299535
Many -Wcharacter-conversion warnings with Clang 21
https://bugs.webkit.org/show_bug.cgi?id=299535
Summary Many -Wcharacter-conversion warnings with Clang 21
Michael Catanzaro
Reported 2025-09-25 11:02:23 PDT
For example: /home/mcatanzaro/Projects/WebKit/Source/WTF/wtf/text/StringConcatenate.h:112:30: error: implicit conversion from 'const char32_t' to 'element_type' (aka 'char16_t') may lose precision and change the meaning of the represented code unit [-Werror,-Wcharacter-conversion] 112 | destination[0] = m_character; | ~ ^~~~~~~~~~~ 1 error generated. /home/mcatanzaro/Projects/WebKit/Source/WTF/wtf/URLHelpers.cpp:174:61: error: implicit conversion from 'char16_t' to 'char32_t' may change the meaning of the represented code unit [-Werror,-Wcharacter-conversion] 174 | return isLookalikeCharacterOfScriptType<ScriptType>(first) && !(isOfScriptType<ScriptType>(second) || isASCIIDigitOrValidHostCharacter(second)); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^~~~~ /home/mcatanzaro/Projects/WebKit/Source/WTF/wtf/URLHelpers.cpp:177:48: error: implicit conversion from 'char32_t' to 'char16_t' may lose precision and change the meaning of the represented code unit [-Werror,-Wcharacter-conversion] 177 | || isLookalikePair(*previousCodePoint, codePoint); | ~~~~~~~~~~~~~~~ ^~~~~~~~~ /home/mcatanzaro/Projects/WebKit/Source/WTF/wtf/URLHelpers.cpp:350:16: note: in instantiation of function template specialization 'WTF::URLHelpers::isLookalikeSequence<USCRIPT_ARMENIAN>' requested here 350 | return isLookalikeSequence<USCRIPT_ARMENIAN>(previousCodePoint, codePoint) | ^ Worse, several of these are coming from ICU headers: /home/mcatanzaro/Projects/WebKit/Source/WTF/wtf/text/StringView.h:1017:5: error: implicit conversion from 'const char16_t' to 'char32_t' may change the meaning of the represented code unit [-Werror,-Wcharacter-conversion] 1017 | U16_GET(static_cast<const char16_t*>(m_current), 0, 0, length, codePoint); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/unicode/utf16.h:202:9: note: expanded from macro 'U16_GET' 202 | (c)=(s)[i]; \ | ~^~~~~~
Attachments
Michael Catanzaro
Comment 1 2025-09-25 11:11:09 PDT
Fixing ICU is pretty easy: diff --git a/icu4c/source/common/unicode/utf16.h b/icu4c/source/common/unicode/utf16.h index 3902c60e95e..43e72a711cc 100644 --- a/icu4c/source/common/unicode/utf16.h +++ b/icu4c/source/common/unicode/utf16.h @@ -165,7 +165,7 @@ * @stable ICU 2.4 */ #define U16_GET_UNSAFE(s, i, c) UPRV_BLOCK_MACRO_BEGIN { \ - (c)=(s)[i]; \ + (c)=(UChar32)(s)[i]; \ if(U16_IS_SURROGATE(c)) { \ if(U16_IS_SURROGATE_LEAD(c)) { \ (c)=U16_GET_SUPPLEMENTARY((c), (s)[(i)+1]); \ @@ -199,7 +199,7 @@ * @stable ICU 2.4 */ #define U16_GET(s, start, i, length, c) UPRV_BLOCK_MACRO_BEGIN { \ - (c)=(s)[i]; \ + (c)=(UChar32)(s)[i]; \ if(U16_IS_SURROGATE(c)) { \ uint16_t __c2; \ if(U16_IS_SURROGATE_LEAD(c)) { \ @@ -238,7 +238,7 @@ * @stable ICU 60 */ #define U16_GET_OR_FFFD(s, start, i, length, c) UPRV_BLOCK_MACRO_BEGIN { \ - (c)=(s)[i]; \ + (c)=(UChar32)(s)[i]; \ if(U16_IS_SURROGATE(c)) { \ uint16_t __c2; \ if(U16_IS_SURROGATE_LEAD(c)) { \ @@ -279,7 +279,7 @@ * @stable ICU 2.4 */ #define U16_NEXT_UNSAFE(s, i, c) UPRV_BLOCK_MACRO_BEGIN { \ - (c)=(s)[(i)++]; \ + (c)=(UChar32)(s)[(i)++]; \ if(U16_IS_LEAD(c)) { \ (c)=U16_GET_SUPPLEMENTARY((c), (s)[(i)++]); \ } \ @@ -307,7 +307,7 @@ * @stable ICU 2.4 */ #define U16_NEXT(s, i, length, c) UPRV_BLOCK_MACRO_BEGIN { \ - (c)=(s)[(i)++]; \ + (c)=(UChar32)(s)[(i)++]; \ if(U16_IS_LEAD(c)) { \ uint16_t __c2; \ if((i)!=(length) && U16_IS_TRAIL(__c2=(s)[(i)])) { \ @@ -339,7 +339,7 @@ * @stable ICU 60 */ #define U16_NEXT_OR_FFFD(s, i, length, c) UPRV_BLOCK_MACRO_BEGIN { \ - (c)=(s)[(i)++]; \ + (c)=(UChar32)(s)[(i)++]; \ if(U16_IS_SURROGATE(c)) { \ uint16_t __c2; \ if(U16_IS_SURROGATE_LEAD(c) && (i)!=(length) && U16_IS_TRAIL(__c2=(s)[(i)])) { \ However, unfortunately ICU has a contributor license agreement, which I'm not going to accept, so I won't submit this to upstream. We need to work around this at the WebKit level anyway since we only control the ICU headers on macOS; on Linux, they are a system dependency.
Michael Catanzaro
Comment 2 2025-09-25 12:20:08 PDT
Unrelated: /home/mcatanzaro/Projects/WebKit/WebKitBuild/gtk4/JavaScriptCore/PrivateHeaders/JavaScriptCore/RemoteInspector.h:135:13: error: virtual method '~RemoteInspector' is inside a 'final' class and can never be overridden [-Werror,-Wunnecessary-virtual-specifier] 135 | virtual ~RemoteInspector(); | ^ 1 error generated.
Michael Catanzaro
Comment 3 2025-09-29 10:00:35 PDT
Darin says: "I reviewed ICU documentation, and I think it’s an error to use U16_GET with char32_t. The output type is supposed to be uint32_t. So that’s why ICU won’t be fixing it!" Well, the actual output type is UChar32. It should be compatible with char32_t in the sense that casting should do the right thing, but it's indeed WebKit's fault for using the wrong type, not an ICU bug. So no need for anybody to try submitting my patch to ICU.
Michael Catanzaro
Comment 4 2025-09-29 13:08:56 PDT
Another note for myself: /home/mcatanzaro/Projects/WebKit/Source/WebKit/UIProcess/AuxiliaryProcessProxy.cpp:166:10: error: variable 'varname' is used uninitialized whenever switch case is taken [-Werror,-Wsometimes-uninitialized] 166 | case ProcessLauncher::ProcessType::DBusProxy: | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /home/mcatanzaro/Projects/WebKit/Source/WebKit/UIProcess/AuxiliaryProcessProxy.cpp:171:43: note: uninitialized use occurs here 171 | const char* processCmdPrefix = getenv(varname); | ^~~~~~~ /home/mcatanzaro/Projects/WebKit/Source/WebKit/UIProcess/AuxiliaryProcessProxy.cpp:147:24: note: initialize the variable 'varname' to silence this warning 147 | const char* varname; | ^ | = nullptr
Michael Catanzaro
Comment 5 2025-09-29 13:14:22 PDT
*** This bug has been marked as a duplicate of bug 299689 ***
Note You need to log in before you can comment on or make changes to this bug.