[Interest] Future of constexpr in Qt?

Thiago Macieira thiago.macieira at intel.com
Mon Nov 25 05:08:47 CET 2024


On Sunday 24 November 2024 05:18:33 Pacific Standard Time Volker Hilsheimer via 
Interest wrote:
> Also, some things that are constexpr in a test might not be constexpr in a
> real program. E.g. std::string can only be constexpr as long as the string
> fits into whatever size the library uses for its small-string optimization.
> As soon as that space is not sufficient, std::string has to allocate using
> operator new, and your code will no longer build.

C++20 does support dynamic memory allocation at constexpr time

https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p0784r7.html

It must be freed before the evaluation terminates, though.

We can detect std::is_constant_evaluated() and use calls to new instead of 
QArrayData::allocate, but every use of std::is_constant_evaluated() implies 
that the code that was checked at constexpr time is not the code that is run 
at runtime.

-- 
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/20241124/748abed9/attachment.bin>


More information about the Interest mailing list