[Development] Deprecating Q_STATIC_ASSERT_X and Q_STATIC_ASSERT

Olivier Goffart olivier at woboq.com
Thu Jun 11 11:37:56 CEST 2020

On 11/06/20 11:11, Edward Welbourne wrote:
> Hi all,
> On [0] there is discussion of deprecating these two macros, or even
> outright removing them in Qt 6.  I see the sense of deprecation, on dev
> at least, since we expect C++17, in which static_assert() does the whole
> job.  Since they're macros, I know of no way to tell the compiler to
> warn about their use, so the only deprecation we can do is in the
> documentation - that doesn't yet exist; that's what [0] is seeking to
> fix.  So the deprecation would simply be a matter of marking them
> \obsolete; in 5.15, we can mark the two-arg form as obsolete (since
> static_assert(cond, msg) exists in C++11) but not the single-arg form.
> [0] https://codereview.qt-project.org/c/qt/qtbase/+/303218
> I also note that there's non-trivial #if-ery, still on dev, to support
> compilers/platforms on which static_assert isn't available.  I have to
> suppose that is redundant, given that we expect a C++11 compiler in 5.15
> and static_assert() is a compiler feature, not a standard library one
> (where we allow some gaps on C++11, IIUC).  So does anyone believe that
> #if-ery is actually still needed - i.e. does anyone believe there is a
> platform for which Q_COMPILER_STATIC_ASSERT *doesn't* get defined in
> qcompilerdetection.h ?
> Assuming there's no such platform, I propose to rip out (from both dev
> and 5.15) Q_COMPILER_STATIC_ASSERT on the premise that it's always
> defined and we can always use static_assert (or, in C, _Static_assert).
> That then leaves the question of whether we deprecate in Qt 6 or remove
> these macros.  I shall leave Marc, who I understand as wanting the
> latter option, to make the case for it, lest I misrepresent that case.
> Are there any compelling reasons to just document these macros and
> retain them, without marking as \obsolete in the docs ?

That's right, Q_STATIC_ASSERT was introduced before C++11 support was required 
in Qt and since C++11 is required, its use is counter productive because one 
get worse error message due to the fact that it is a macro indirection.
(even the fact that one does not need a message in it is not a good reason to 
use it instead of static_assert(foo, "...");)

With a bit of creativity, it is not too difficult to find a way to show a 
compiler warning on its use. For example:

[[deprecated]] constexpr bool Q_STATIC_ASSERT_IS_DEPRECATED()    {
     return true;

#define Q_STATIC_ASSERT(cond) static_assert(Q_STATIC_ASSERT_IS_DEPRECATED() && 


More information about the Development mailing list