[Core] Add KRATOS_DEPRECATED_ERROR macro for compile-time deprecation enforcement#14466
Conversation
|
As I mentioned in #14461, the problem with this approach is that we'll never be able to compile earlier versions (unless someone resets their system time or changes this macro). |
|
this was rejected in the past bcs users would just start to meddle with the systems time etc. Imagine how annoying this would be to use on a cluster. You want to run the final sims for your phd project, and then get hit with such an error because somebody refactored sth |
yes I remember, but I don't have any other idea...if you have a better suggestion we can use this as base |
|
I think the only way is to have depreciation warnings telling the user what to do Depending on what changes dictates the deprecation period. IMO large things like elements in major apps should remain for at least half a year |
name: ✨ Feature
about: Add
KRATOS_DEPRECATED_ERRORmacro for compile-time deprecation enforcement.📝 Description
Adds a new macro
KRATOS_DEPRECATED_ERRORtokratos/includes/define.hthat causes a compile-time error once a specified deadline date is reached. This complements the existingKRATOS_DEPRECATED_MESSAGE(which emits a deprecation warning) by providing a hard enforcement mechanism: code marked with this macro will simply refuse to compile past its deadline, ensuring deprecated APIs are actually removed.Fixes #14461 ?
Typical usage
Inside a function body, at class scope, or at namespace scope:
When the deadline passes, the compiler emits a clear error pointing to the macro call site, including the deadline date and the developer-supplied message:
Key changes
KRATOS_DEPRECATED_ERROR(year, month, day, message)added alongsideKRATOS_DEPRECATEDandKRATOS_DEPRECATED_MESSAGEinkratos/includes/define.h. Expands to astatic_assertthat compares the compile date against the given deadline. The assert fires on the dead line day itself (strictly<).constexprhelpers added in a newnamespace Kratos::Internalsblock inside the existingnamespace Kratossection ofdefine.h:DeprecationMonthToInt(const char*)— maps the 3-letter month string from__DATE__to an integer 1–12.CompileDateAsInt(const char*)— parses the__DATE__predefined macro ("Mon DD YYYY") into a YYYYMMDD integer for comparison.DeadlineDateAsInt(int, int, int)— packs the (year, month, day) macro arguments into the same YYYYMMDD format.No changes to CMake, Python bindings, or application code are needed — the macro is purely a header-level addition and the constexpr helpers are zero-overhead (evaluated entirely at compile time).
Validation
2099-12-31) — compiles without error.2020-01-01) — produces the expectedstatic_asserterror with the correct message and comparison values printed by the compiler.🆕 Changelog
KRATOS_DEPRECATED_ERROR(year, month, day, message)macro tokratos/includes/define.hto enforce hard compile-time removal deadlines on deprecated code.