1

As the title states, I'm wondering if I can mark a function as "deprecating", or simply output a message during compilation that is not a warning or error.

I do not want to prevent compilation of currently functioning applications, simply notify developers that we plan to deprecate a function or constructor in the future (and perhaps add a message detailing when it will be deprecated), so that they can make changes when time is available.

I'm aware of functionality such as

[[deprecated("message")]] foo();

But I can't find any information on anything that won't produce a warning or error.

Must be usable on G++ v7.0 or higher (C++17 or under)

Ðаn
  • 10,934
  • 11
  • 59
  • 95
cbrng
  • 63
  • 4
  • 1
    You might try this: https://stackoverflow.com/questions/1759352/how-to-mark-a-method-as-obsolete-or-deprecated – Ricardo Ortega Magaña Aug 09 '21 at 18:07
  • 1
    Personally I would just produce a warning. People that want to ignore them can, and people that don't will be happy they have a diagnostic message for each place they used the thing that is being deprecated. – NathanOliver Aug 09 '21 at 18:10
  • @NathanOliver Ideally that's what I would do as well, however we have warnings set to errors which would prevent compilation of production level applications, and this we cannot have. The function won't be completely deprecated until all applications are upgraded to use the newer functions, however we may not have the time to do so immediately with everything. – cbrng Aug 09 '21 at 18:11
  • If you used `-pedantic-errors` which makes only the Standard Violations `errors` (instead of `-Werror`) - would that be pedantic enough to allow warnings to pass? – Galik Aug 09 '21 at 18:13
  • "Deprecate" is a term of art in standardization. It means that something might go away in the future. Notifying developers that you might decide in the future that something might go away in the future seems rather baroque. – Pete Becker Aug 09 '21 at 18:14
  • 1
    `-Wno-error=deprecated-declarations` will revert deprecations back to non-fatal warnings, despite `-Werror` –  Aug 09 '21 at 18:14
  • @cbrng You should be able to add `-Wno-deprecated-declarations` to your compiler flags to allow it to still compile. – NathanOliver Aug 09 '21 at 18:14
  • Sounds like *premature deprecation*, since you are informing that something may (presumably *likely may*) be deprecated. Just put that in a comment in the header. When Apple deprecates something, usually (in the past 20 years, don't look at QuickDraw GX history) it's something that they just let glide, until they *officially* deprecate it. (I'm looking at you, OpenGL.) Then 2 or 3 releases later after officially deprecating it, they EOL-and-remove it. – Eljay Aug 09 '21 at 18:19

1 Answers1

1

Your best option is to keep using [[deprecated("message")]]. It's the official way to mark deprecation after all.

In order to prevent the warnings from causing build errors while still maintaining -Werror, you can "downgrade" the error back into a warning.

This can be done as a compilation flag: -Wno-error=deprecated-declarations.

Or directly in the code:

#pragma GCC diagnostic push
#pragma GCC diagnostic warning "-Wdeprecated-declarations"

// Insert code that has non-fatal deprecation warnings

#pragma GCC diagnostic pop