Go to file
Marc Mutz 8ea27bb1c6 Make Q_ASSERT() usable in constexpr functions
We need Q_ASSERT in (C++11) constexpr functions, and the only way to
inject them in C++11 is to use the comma operator. E.g. in
QLatin1String:

    constexpr QLatin1Char at(int i) const
    { return assert(1 >= 0), assert(i < size()), m_data[i]; }

The main problem with our existing Q_ASSERT is that while it is a
ternary expression in active mode, it was a statement in passive
mode. This is easily fixed by dropping the do-while loop and leaving
just its parenthesized exit condition. Add a cast to void, too,
ensuring that Q_ASSERT has type void in both passive and active modes.

But even in C++14 constexpr functions, which accept several
statements, Q_ASSERT needs to have a path through its conditionals
that is constexpr, but neither qt_assert(_x) nor qt_noop() are
constexpr. Nor can they be in C++11 (no void returns in C++11
constexpr functions). I fixed this by replacing qt_noop() with
static_cast<void>(0). The void cast is required so both 2nd and 3rd
arguments to the ternary are void (mixing void and non-void branches
in the ternary is only allowed if the void leg is a
throw-expression[1]).

As a drive-by, adjust to style guide, remove overparenthesization and
reverse the conditional in the ternary.

Apply it to QLatin1String where we had the problem that constexpr
functions had a narrow constract.

[1] should probably be extended to any [[noreturn]] void function,
e.g. std::terminate().

[ChangeLog][QtCore][QtGlobal] Q_ASSERT() and Q_ASSERT_X() now always
expand to expressions of type void that are usable in constexpr
contexts. This makes them usable in both C++11 and C++14 constexpr
functions.

Change-Id: I09c396bc0034ac344cfaadc6f8cbeb1b7b0cbabc
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
2017-03-16 14:11:16 +00:00
bin don't include injected headers into linker version script 2016-10-14 09:00:29 +00:00
config.tests Merge remote-tracking branch 'origin/5.9' into dev 2017-03-14 10:52:24 +01:00
dist Add changes file for 5.8.0 2017-01-02 06:50:47 +00:00
doc Merge remote-tracking branch 'origin/5.9' into dev 2017-03-14 10:52:24 +01:00
examples Deprecate QSignalMapper 2017-03-14 16:33:59 +00:00
lib Purge all fonts 2015-08-18 19:59:14 +00:00
mkspecs Merge remote-tracking branch 'origin/5.9' into dev 2017-03-14 10:52:24 +01:00
qmake Merge remote-tracking branch 'origin/5.9' into dev 2017-03-14 10:52:24 +01:00
src Make Q_ASSERT() usable in constexpr functions 2017-03-16 14:11:16 +00:00
tests Make QWindow's windowState a QFlags of the WindowState 2017-03-16 12:55:19 +00:00
util Also release winmain, qopenglextensions under commercial licenses 2016-11-18 16:19:56 +00:00
.gitattributes Update the git-archive export options 2012-09-07 15:39:31 +02:00
.gitignore Overhaul .gitignore 2017-02-16 15:11:05 +00:00
.qmake.conf Bump version 2017-02-03 12:01:58 +00:00
.tag Update the git-archive export options 2012-09-07 15:39:31 +02:00
config_help.txt Merge remote-tracking branch 'origin/5.8' into 5.9 2017-02-24 20:01:42 +01:00
configure complain about various invalid configuration attempts 2017-01-06 20:10:10 +00:00
configure.bat reduce nesting in configure.bat 2017-01-10 12:44:21 +00:00
configure.json Merge remote-tracking branch 'origin/5.9' into dev 2017-03-02 09:04:38 +01:00
configure.pri Merge remote-tracking branch 'origin/5.8' into 5.9 2017-02-08 15:49:18 +01:00
header.BSD Add new license header templates and license files 2016-01-14 20:43:46 +00:00
header.BSD-OLD Add new license header templates and license files 2016-01-14 20:43:46 +00:00
header.COMM Add header template for commercial only modules 2015-10-19 10:37:18 +00:00
header.FDL Add new license header templates and license files 2016-01-14 20:43:46 +00:00
header.FDL-OLD Add new license header templates and license files 2016-01-14 20:43:46 +00:00
header.GPL Add new license header templates and license files 2016-01-14 20:43:46 +00:00
header.GPL-EXCEPT Add new license header templates and license files 2016-01-14 20:43:46 +00:00
header.LGPL Add new license header templates and license files 2016-01-14 20:43:46 +00:00
header.LGPL3 Update copyright headers 2015-02-11 06:49:51 +00:00
header.LGPL3-COMM Update copyright headers 2015-02-11 06:49:51 +00:00
header.LGPL21 Update copyright headers 2015-02-11 06:49:51 +00:00
header.LGPL-NOGPL2 Add new license header templates and license files 2016-01-14 20:43:46 +00:00
header.LGPL-ONLY Update copyright headers 2015-02-11 06:49:51 +00:00
INSTALL Doc: Update links in INSTALL file 2015-02-16 09:06:41 +00:00
LGPL_EXCEPTION.txt Update copyright headers 2015-02-11 06:49:51 +00:00
LICENSE.FDL Initial import from the monolithic Qt. 2011-04-27 12:05:43 +02:00
LICENSE.GPL2 Add new license header templates and license files 2016-01-14 20:43:46 +00:00
LICENSE.GPL3 Add new license header templates and license files 2016-01-14 20:43:46 +00:00
LICENSE.GPL3-EXCEPT Add new license header templates and license files 2016-01-14 20:43:46 +00:00
LICENSE.GPLv3 Expand license scope from "Qt GUI Toolkit" to "Qt Toolkit" 2016-06-15 07:02:32 +00:00
LICENSE.LGPL3 Add new license header templates and license files 2016-01-14 20:43:46 +00:00
LICENSE.LGPLv3 Expand license scope from "Qt GUI Toolkit" to "Qt Toolkit" 2016-06-15 07:02:32 +00:00
LICENSE.LGPLv21 Expand license scope from "Qt GUI Toolkit" to "Qt Toolkit" 2016-06-15 07:02:32 +00:00
LICENSE.PREVIEW.COMMERCIAL Add new license header templates and license files 2016-01-14 20:43:46 +00:00
qtbase.pro nuke configure -host-option 2016-12-13 18:55:59 +00:00
sync.profile Merge remote-tracking branch 'origin/5.8' into dev 2016-11-17 14:43:26 +01:00