path: root/src/corelib/global
diff options
authorThiago Macieira <>2015-03-05 09:31:20 -0800
committerLiang Qi <>2015-03-06 06:19:47 +0000
commit9a3d7adaad367417aaa2e1ee1f996185a881a4b5 (patch)
tree7870a176c5c5c737ff3740f4e47d932156cf3c1f /src/corelib/global
parent4fe9798db3e32aae45d79bef7c1c82e50933658a (diff)
Fix -Wunreachable-code warning from clang in preprocessed Q_ASSERT
Q_ASSERT expands to: do {} while (false && (<your condition>)) Which is fine for Clang as long as it's a macro. However, when you compile as a preprocessed source, the macro is gone and Clang prints the warning: warning: code will never be executed [-Wunreachable-code] do {} while (false && (f())); ^ note: silence by adding parentheses to mark code as explicitly dead So add the parentheses that it's asking about. The changelog refers to the full Q_ASSERT change from ebef2ad1360c80ad62de5f4a1c4e7e4051725c1c. [ChangeLog][Important Behavior Changes] Q_ASSERT will now expand the condition even in release mode when asserts are disabled, albeit in an unreachable code path. This solves compiler warnings about variables and functions that were unused in release mode because they were only used in assertions. Unfortunately, codebases that hid those functions and variables via #ifndef will need to remove the conditionals to compile with Qt 5.5. Change-Id: Ia0aac2f09e9245339951ffff13c8aa70229254d0 Reviewed-by: Olivier Goffart (Woboq GmbH) <>
Diffstat (limited to 'src/corelib/global')
1 files changed, 1 insertions, 1 deletions
diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h
index a171f0894b..92027611b5 100644
--- a/src/corelib/global/qglobal.h
+++ b/src/corelib/global/qglobal.h
@@ -660,7 +660,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) do { } while (false && (cond))
+# define Q_ASSERT(cond) do { } while ((false) && (cond))
# else
# define Q_ASSERT(cond) ((!(cond)) ? qt_assert(#cond,__FILE__,__LINE__) : qt_noop())
# endif