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

Need a (private) function to express cast-or-assert

XMLWordPrintable

    • Icon: Task Task
    • Resolution: Unresolved
    • Icon: P2: Important P2: Important
    • None
    • None
    • Core: Other
    • None
    • Foundation PM Prioritized

      We have q26::saturate_cast, which saturates, but we might also benefit from a checked narrowing conversion, that fails on out-of-range value instead of saturating, e.g. uint -> ushort, or, in the presence of Clang 21's -Wcharacter-conversion, char32_t -> char16_t. Currently, we either rely (in implementation) on old C semantics (where these are implicit and warning-free) or do them with an explicit cast (in headers, where -Wshorten-64-to-32 and -Wnarrowing are in effect for headerscheck).

      This came up in several code changes recently, though I can't recall which ones, exactly, but I'm confident that we'll find lots of users for this function once it lands.

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

            thiago Thiago Macieira
            mmutz Marc Mutz
            Vladimir Minenko Vladimir Minenko
            Alex Blasche Alex Blasche
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:

                There are no open Gerrit changes