[Interest] Future of constexpr in Qt?
Thiago Macieira
thiago.macieira at intel.com
Fri Nov 22 17:14:40 CET 2024
On Thursday 21 November 2024 23:14:30 Pacific Standard Time Schimkowitsch
Robert wrote:
> Hi Volker,
>
> do you think that the language (let's say up to 23, because constexpr could
> be a conditional macro anyway) would even allow making constexpr useful,
> bigger portions such as
> - basic implicit sharing mechanism
> - basic usage of QString
> - basic usage of QList?
Yes, we looked into that but that caused the build to break with Clang,
because it changes how aggressive it instantiates templates in
QArrayDataPointer if they are constexpr. That causes the build to break for
non-constexpr contexts. Right now, this work is postponed until we figure out
what we can do.
One idea is to support constexpr QString and QByteArray, and maybe QLists of
trivial types, but not for anything else.
> These are so common in our codebase that without them, only a relatively few
> functions can ever be made constexpr.
You will be able to create and destroy QString and QByteArray, find out if they
are empty or not, get the pointer to the data, but not call almost any other
methods in them.
> Herb Sutter highlighted constexpr as a way to increase programming language
> safety in his recent keynote at Meeting C++. Things like making a runtime
> function constexpr, so you can, at compile time, check for UB using
> static_asserts or such when feeding it with various ranges of values (min,
> max, zero, empty list,...). Now I'm thinking about how we could apply those
> ideas in real code - and Qt mostly stops us from doing that, right there
> and then.
That's a fallacy.
The fact that you can do it under constexpr doesn't magically make the same
usage safe when not under constexpr.
--
Thiago Macieira - thiago.macieira (AT) intel.com
Principal Engineer - Intel DCAI Platform & System Engineering
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 5152 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20241122/3e1a9e49/attachment.bin>
More information about the Interest
mailing list