Use the C++ [[nodiscard]] attribute

Change-Id: I7814054a102a407d876ffffd14b6a285c70b21de
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
bb10
Thiago Macieira 2017-04-18 16:43:41 -07:00
parent 6ae801875e
commit d254d8c197
3 changed files with 38 additions and 33 deletions

View File

@ -1060,6 +1060,37 @@
# endif
#endif
/*
* SG10's SD-6 feature detection and some useful extensions from Clang and GCC
* https://isocpp.org/std/standing-documents/sd-6-sg10-feature-test-recommendations
* http://clang.llvm.org/docs/LanguageExtensions.html#feature-checking-macros
*/
#ifdef __has_builtin
# define QT_HAS_BUILTIN(x) __has_builtin(x)
#else
# define QT_HAS_BUILTIN(x) 0
#endif
#ifdef __has_attribute
# define QT_HAS_ATTRIBUTE(x) __has_attribute(x)
#else
# define QT_HAS_ATTRIBUTE(x) 0
#endif
#ifdef __has_cpp_attribute
# define QT_HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x)
#else
# define QT_HAS_CPP_ATTRIBUTE(x) 0
#endif
#ifdef __has_include
# define QT_HAS_INCLUDE(x) __has_include(x)
#else
# define QT_HAS_INCLUDE(x) 0
#endif
#ifdef __has_include_next
# define QT_HAS_INCLUDE_NEXT(x) __has_include_next(x)
#else
# define QT_HAS_INCLUDE_NEXT(x) 0
#endif
/*
* C++11 keywords and expressions
*/
@ -1141,6 +1172,11 @@
# define Q_DECL_ALIGN(n) alignas(n)
#endif
#if QT_HAS_CPP_ATTRIBUTE(nodiscard) // P0188R1
# undef Q_REQUIRED_RESULT
# define Q_REQUIRED_RESULT [[nodiscard]]
#endif
/*
* Fallback macros to certain compiler features
*/
@ -1215,37 +1251,6 @@
#ifndef QT_MAKE_CHECKED_ARRAY_ITERATOR
# define QT_MAKE_CHECKED_ARRAY_ITERATOR(x, N) (x)
#endif
/*
* SG10's SD-6 feature detection and some useful extensions from Clang and GCC
* https://isocpp.org/std/standing-documents/sd-6-sg10-feature-test-recommendations
* http://clang.llvm.org/docs/LanguageExtensions.html#feature-checking-macros
*/
#ifdef __has_builtin
# define QT_HAS_BUILTIN(x) __has_builtin(x)
#else
# define QT_HAS_BUILTIN(x) 0
#endif
#ifdef __has_attribute
# define QT_HAS_ATTRIBUTE(x) __has_attribute(x)
#else
# define QT_HAS_ATTRIBUTE(x) 0
#endif
#ifdef __has_cpp_attribute
# define QT_HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x)
#else
# define QT_HAS_CPP_ATTRIBUTE(x) 0
#endif
#ifdef __has_include
# define QT_HAS_INCLUDE(x) __has_include(x)
#else
# define QT_HAS_INCLUDE(x) 0
#endif
#ifdef __has_include_next
# define QT_HAS_INCLUDE_NEXT(x) __has_include_next(x)
#else
# define QT_HAS_INCLUDE_NEXT(x) 0
#endif
#ifdef __has_feature
# define QT_HAS_FEATURE(x) __has_feature(x)
#else

View File

@ -243,7 +243,7 @@ public:
void chop(int n);
#if defined(Q_COMPILER_REF_QUALIFIERS) && !defined(QT_COMPILING_QSTRING_COMPAT_CPP) && !defined(Q_CLANG_QDOC)
# if defined(Q_CC_GNU) && !defined(Q_CC_CLANG) && !defined(Q_CC_INTEL)
# if defined(Q_CC_GNU) && !defined(Q_CC_CLANG) && !defined(Q_CC_INTEL) && !QT_HAS_CPP_ATTRIBUTE(nodiscard)
// required due to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61941
# pragma push_macro("Q_REQUIRED_RESULT")
# undef Q_REQUIRED_RESULT

View File

@ -383,7 +383,7 @@ public:
Q_REQUIRED_RESULT QString rightJustified(int width, QChar fill = QLatin1Char(' '), bool trunc = false) const;
#if defined(Q_COMPILER_REF_QUALIFIERS) && !defined(QT_COMPILING_QSTRING_COMPAT_CPP) && !defined(Q_CLANG_QDOC)
# if defined(Q_CC_GNU) && !defined(Q_CC_CLANG) && !defined(Q_CC_INTEL)
# if defined(Q_CC_GNU) && !defined(Q_CC_CLANG) && !defined(Q_CC_INTEL) && !QT_HAS_CPP_ATTRIBUTE(nodiscard)
// required due to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61941
# pragma push_macro("Q_REQUIRED_RESULT")
# undef Q_REQUIRED_RESULT