[Development] Fw: How to do deprecation

Edward Welbourne edward.welbourne at qt.io
Thu Jul 21 11:22:48 CEST 2022

Lars wrote:
>> So instead of
>>     QT_DEPRECATED_VERSION_X_6_4("Use size() or length() instead.")
>>     inline qsizetype count() const { return d.size; }
>> #endif
>> You’d have:
>>     QT_DEPRECATED_METHOD(qsizetype count(), 6, 4, "Use size() or length() instead.”)

Jaroslaw Kobus (21 July 2022 09:51) replied:
> it would be really cool to have it like this. However, just joining
> small and simple step forward.

The thing is, the only way to do that is indeed to do it in the form of
a macro such as Lars described, since the results of preprocessing must
be capable of producing:
* No declaration at all
* The declaration with a [[deprecated]] marker
* The plain declaration

and the C preprocessor is very simple in its capabilities.  In
particular, you can't cause the #if-ery round some code to define a
scope in which all declarations are automagically preceded with a
deprecation marker, so you can't get away from needing a macro applied
to each of the declarations; and that can't vanish entirely unless every
part of the declaration is packaged in its parameters (since anything
outside its parameter list will still be seen by the compiler), unless
you separately wrap it in #if-ery.  So what Lars proposes is the only
way to unify the two present intrusions into code.


More information about the Development mailing list