Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-141204

Deal with Clang 21's -Wcharacter-conversion warning

XMLWordPrintable

    • Icon: Epic Epic
    • Resolution: Unresolved
    • Icon: P2: Important P2: Important
    • None
    • None
    • Core: Other, Other
    • None
    • Clang 21 -Wcharacter-conversion
    • 21
    • 002aed143 (dev), 8279812b5 (6.10), dbcd1a538 (tqtc/lts-6.8)

      Clang 21 added a new warning, -Wcharacter-conversions, which warns about all conversions (incl. comparisons) between char8_t, char16_t, char32_t. There's a hope they'll remove the warning for char16_tchar32_t again, because that currently wreaks havoc in the C++ world, or move this conversion to a different warning (level).

      For now, we want to fix all these warnings in headers (which means it should be added to headerscheck), but in implementation files only fix those that are not about char16_tchar32_t.

      Preferably, fixing involves more than slapping an explicit cast on the narrowing conversion. E.g. we have the following pattern quite widespread:

      const char16_t *p = ~~~~;
      char32_t uc = *p++;
      if (QChar::isSurrogate(uc) && in-range)
          uc = QChar::surrogateToUcs4(uc, *p++);
      use(uc);
      

      which prompts this warning (for both 16 → 32 and 32 → 16), but is readily fixed not as char16_t(uc), but as

      const char16_t *p = ~~~~;
      const char16_t c = *p++;
      char32_t uc; // uninit'ed, to give the compiler the option of warning about it
      if (QChar::isSurrogate(c) && in-range)
          uc = QChar::surrogateToUcs4(c, *p++);
      else
          uc = c;
      use(uc);
       

      Acceptance criteria:

      • -Wcharacter-conversion is part of headerscheck
      • all warnings from -Wcharacter-conversion that are not about char16_tchar32_t are fixed (see above for what "fix" means)
      • rest is suppressed

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            mmutz Marc Mutz
            mmutz Marc Mutz
            Vladimir Minenko Vladimir Minenko
            Alex Blasche Alex Blasche
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:

                There are no open Gerrit changes