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

Verify that invokeMethod() on a [[nodiscard]] function doesn't warn (or does warn?)

    XMLWordPrintable

Details

    • Task
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • None
    • Core: Object Model
    • None
    • 13
    • Foundation PM Staging

    Description

      Continuation of the discussion from https://codereview.qt-project.org/c/qt/qtbase/+/585813/comments/216bf93f_3fa018aa

      Background

      This is about having a callable object whose function-call operator is marked as [[nodiscard]]. When calling such function-like objects while ignoring the return value:

      func();
      

      the compiler will warn that a [nodiscard] result was discarded. To fix the warning, you have to either receive the result (and [[maybe_unused]] it, if you don't use it further):

      [[maybe_unused]] auto r = func();
      

      or explicitly cast to void:

      (void)func(); // beware -Wold-style-cast, though
      

      In Qt, such functions / function objects can also be called by QMetaObject::invokeMethod() and QObject::connect(). The task is about warnings that might occur when such functions are called through those mechanisms. There are likely more places in Qt with the same issue. If you find more, create follow-up tickets.

      Acceptance criteria:

      1. write a test that confirms that [[nodiscard]] signals and slot-like objects used in new-style connects do not throw a -Wunused warning (likely in moc code)
      2. determine whether we can know statically whether a qReturnArg() was passed to invokeMethod()
        1. if we can:
          • add a test that we don't warn about -Wunused when a qReturnArg() is passed
          • optionally add a test that we do warn when no qReturnArg() was passed
        2. otherwise:
          • try to massage the overload set so that we can statically know whether qReturnArg() was passed
        3. failing that:
          • add a test that we don't warn in either case

      Attachments

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

        Activity

          People

            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

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes