diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2014-09-10 20:37:51 -0700 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2014-11-01 00:30:37 +0100 |
commit | ebef2ad1360c80ad62de5f4a1c4e7e4051725c1c (patch) | |
tree | 07bf59e33501a24cee376efc0d2955b34df476c3 /src/corelib | |
parent | 791c975c55d26c639d205b58152fd5e9b5f3a85d (diff) |
Make the empty Q_ASSERT still check its argument for validity
With the side-effect that variables and functions in the argument are
now "used". This means we don't need to #ifndef functions only used in
assertions: the compiler will eliminate them by dead code elimination.
Due to the mandatory short-circuiting of the condition, no functions
will ever be called and this expands to no more code than before.
On the negative side, because we won't get warnings for unused variables
initialized outside the Q_ASSERT, non-inlineable calls will not be
elminated by dead code elimination, so they will remain in release code
without warnings.
Because of the expanded code now in Q_ASSERT, the Intel compiler's
optimizer gets thrown: it complains that the non-void function is
failing to return anything, so I had to add two return statements.
Change-Id: I1bb79c9637a2771ef1ec093f901b8d2443788bd6
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@digia.com>
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/global/qglobal.h | 2 | ||||
-rw-r--r-- | src/corelib/io/qtemporaryfile.cpp | 1 | ||||
-rw-r--r-- | src/corelib/kernel/qtranslator.cpp | 1 |
3 files changed, 3 insertions, 1 deletions
diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h index 928bf13835..4a21ab88d8 100644 --- a/src/corelib/global/qglobal.h +++ b/src/corelib/global/qglobal.h @@ -655,7 +655,7 @@ Q_CORE_EXPORT void qt_assert(const char *assertion, const char *file, int line) #if !defined(Q_ASSERT) # if defined(QT_NO_DEBUG) && !defined(QT_FORCE_ASSERTS) -# define Q_ASSERT(cond) qt_noop() +# define Q_ASSERT(cond) do { } while (false && (cond)) # else # define Q_ASSERT(cond) ((!(cond)) ? qt_assert(#cond,__FILE__,__LINE__) : qt_noop()) # endif diff --git a/src/corelib/io/qtemporaryfile.cpp b/src/corelib/io/qtemporaryfile.cpp index 4a9aafcf0b..c96d0504f4 100644 --- a/src/corelib/io/qtemporaryfile.cpp +++ b/src/corelib/io/qtemporaryfile.cpp @@ -222,6 +222,7 @@ static bool createFileFromTemplate(NativeFileHandle &file, } Q_ASSERT(false); + return false; } //************* QTemporaryFileEngine diff --git a/src/corelib/kernel/qtranslator.cpp b/src/corelib/kernel/qtranslator.cpp index 33827926c6..5687a6c3a3 100644 --- a/src/corelib/kernel/qtranslator.cpp +++ b/src/corelib/kernel/qtranslator.cpp @@ -273,6 +273,7 @@ static uint numerusHelper(int n, const uchar *rules, uint rulesSize) } Q_ASSERT(false); + return 0; } class QTranslatorPrivate : public QObjectPrivate |