From 9a3d7adaad367417aaa2e1ee1f996185a881a4b5 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 5 Mar 2015 09:31:20 -0800 Subject: Fix -Wunreachable-code warning from clang in preprocessed Q_ASSERT Q_ASSERT expands to: do {} while (false && ()) 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) --- src/corelib/global/qglobal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/corelib') 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 -- cgit v1.2.3