Details
-
Task
-
Resolution: Unresolved
-
P3: Somewhat important
-
None
-
None
-
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:
- 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)
- determine whether we can know statically whether a qReturnArg() was passed to invokeMethod()
- 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
- otherwise:
- try to massage the overload set so that we can statically know whether qReturnArg() was passed
- failing that:
- add a test that we don't warn in either case
- if we can: