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

Impact of C++20 constexpr on our code

XMLWordPrintable

    • Icon: Epic Epic
    • Resolution: Unresolved
    • Icon: P3: Somewhat important P3: Somewhat important
    • None
    • None
    • Core: Other
    • None
    • C++20 constexpr @ Qt

      C++20 added futher relaxations for constexpr functions:

      1. virtual function calls
      2. dynamic_cast and polymorphic typeid
      3. try-catch blocks
      4. asm, unless "executed" (__cpp_constexpr >= 201907L)
      5. T t; (default initialisation) (__cpp_constexpr >= 201907L)
      6. changing the active member of a union (__cpp_constexpr >= 202002L)
      7. memory allocation and deallocation ("constexpr std::string and std::vector") (defined(__cpp_constexpr_dynamic_alloc))

      As these are all not backwards-compatible with C++17, so all we can realistically do is try and make some interesting functions or classes C++20 constexpr, much like we did in C++11 and C++14 (Q_RELAXED_CONSTEXPR).

      For that, we might want to add a Q_CPP20_CONSTEXPR, though the extensions enumerated above have been merged into the IS in different meetings, so the __cpp_constexpr macro has several potential values on it's way to full C++20 conformance, so one macro may not be sufficient, or we need to use __cpp_constexpr manually (at least we wouldn't need to check for it to be defined anymore, one might hope, simplifying the condition to #if __cpp_constexpr >= 201907L).

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

            cnn Qt Core & Network
            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