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
ebef2ad136.

[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) <ogoffart@woboq.com>
This commit is contained in:
Thiago Macieira 2015-03-05 09:31:20 -08:00 committed by Liang Qi
parent 4fe9798db3
commit 9a3d7adaad

View File

@ -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