[Development] (Bikeshed, pedantic) East constexpr vs West constexpr

Volker Hilsheimer volker.hilsheimer at qt.io
Thu Sep 19 16:33:10 CEST 2024


> On 19 Sep 2024, at 16:18, Thiago Macieira <thiago.macieira at intel.com> wrote:
> 
> On Thursday 19 September 2024 00:55:15 GMT-7 David Redondo wrote:
>> So related blog I read some time ago about this and the "natural order" of
>> qualifiers:
>> 
>> https://quuxplusone.github.io/blog/2021/04/03/static-constexpr-whittling-kni
>> fe/
> 
> Thanks David. Arthur proposes:
> 
>    Attributes-friendness-storage-constness-virtualness-explicitness-
> signedness-length-type Identifier.
> 
> static and inline are storage specifiers, so they go both before constexpr and 
> we prefer "static inline" where both are permitted or required. I think this 
> is a good suggestion to adopt.
> 
> Arthur doesn't conclude very well whether constinit comes all the way first 
> (because it modifies how the initialisation happens) versus being placed where 
> constexpr would be.
> 
> -- 
> Thiago Macieira


My preference would be "static constexpr inline”, as static is the most important piece of information (storage and calling convention in case of member functions), constexpr is “good to know”, and inline is in practice mostly an implementation detail.

It also has the advantage that it keeps code grep-friendly, i.e. I can search for anything “static constexpr” (which for out-of-lined members is the clear preference in existing code), and find everything, even if it’s also inline.

Volker




More information about the Development mailing list