Details
-
Task
-
Resolution: Fixed
-
P2: Important
-
None
-
None
-
3
-
959800f6d (dev)
-
Foundations Sprint 79, Foundations Sprint 80, Foundation Sprint 81
Description
We'd like to apply [[nodiscard]] to our RAII class' ctors (cf. epic for why), and we need to find out whether we need a macro for that in qcompilerdetection.h.
For compilers that don't, check whether they act on __attribute__((__warn_unused_result__)) instead.
Test case:
QMutex mut;
QMutexLocker<QMutex>{&mut}; // Clang already warns b/c of class-level [[nodiscard]], GCC does not
Acceptance criteria:
- proove that all compilers syntactially support [[nodiscard]] on ctors
- semantically, it's ok if they ignore it w/o warning
- or else add a macro Q_NODISCARD_CTOR to qcompilerdetection.h, expanding to
- [[nodiscard]]
- or __attribute__((__warn_unused_result__))
- or nothing, depending on what the particular compiler supports on ctors.
- add a test (can only be syntax-only, but add nonetheless)
The 5min way to solve this is
#if __has_cpp_attribute(nodiscard) >= 201907L # define Q_NODISCARD_CTOR [[nodiscard]] #else # define Q_NODISCARD_CTOR #endif
but that would mean it's limited to C++20, while we'd really like this to be available in C++17, too.
Attachments
Issue Links
- blocks
-
QTBUG-104164 Apply [[nodiscard]] to ctors where useful [QtBase]
-
- Closed
-
-
QTBUG-104168 Apply [[nodiscard]] to ctors where useful [QtDeclarative]
-
- Closed
-
-
QTBUG-104169 Apply [[nodiscard]] to ctors where useful [QtConnectivity]
-
- Closed
-
- relates to
-
QTBUG-104167 [spike] Create a policy for [[nodiscard]] on ctors
-
- Closed
-