Skip to content

Commit

Permalink
Make the empty Q_ASSERT still check its argument for validity
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
thiagomacieira committed Oct 31, 2014
1 parent 791c975 commit ebef2ad
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/corelib/global/qglobal.h
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/corelib/io/qtemporaryfile.cpp
Expand Up @@ -222,6 +222,7 @@ static bool createFileFromTemplate(NativeFileHandle &file,
}

Q_ASSERT(false);
return false;
}

//************* QTemporaryFileEngine
Expand Down
1 change: 1 addition & 0 deletions src/corelib/kernel/qtranslator.cpp
Expand Up @@ -273,6 +273,7 @@ static uint numerusHelper(int n, const uchar *rules, uint rulesSize)
}

Q_ASSERT(false);
return 0;
}

class QTranslatorPrivate : public QObjectPrivate
Expand Down
2 changes: 0 additions & 2 deletions src/gui/text/qtextdocument_p.cpp
Expand Up @@ -125,14 +125,12 @@ static bool isValidBlockSeparator(QChar ch)
|| ch == QTextEndOfFrame;
}

#if !defined(QT_NO_DEBUG) || defined(QT_FORCE_ASSERTS)
static bool noBlockInString(const QString &str)
{
return !str.contains(QChar::ParagraphSeparator)
&& !str.contains(QTextBeginningOfFrame)
&& !str.contains(QTextEndOfFrame);
}
#endif

bool QTextUndoCommand::tryMerge(const QTextUndoCommand &other)
{
Expand Down

0 comments on commit ebef2ad

Please sign in to comment.