D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 9395 - Allow deprecated statement in enum members
Summary: Allow deprecated statement in enum members
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 enhancement
Assignee: No Owner
URL:
Keywords:
: 10362 (view as issue list)
Depends on:
Blocks:
 
Reported: 2013-01-25 17:48 UTC by Andrej Mitrovic
Modified: 2019-05-11 20:50 UTC (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Andrej Mitrovic 2013-01-25 17:48:41 UTC
Let's say you have an existing enum in your library API:

enum SpanMode
{
    depth,
    breadth,
    shallow,
}

At some point you may decide you want to rename some of the members, but want to avoid code breakage for at least some time. You could introduce additional members which have the same values as the old ones:

enum SpanMode
{
    deep,  // new
    wide,  // new 
    shallow,

    depth = deep,  // old
    breadth = wide,  // old
}

This will work with switches, final switches, to!string, etc (although code that depends on EnumMembers!E.length could potentially break depending on what it does).

Don't mind the naming choice (it's just an example), but it would be useful to allow a deprecated statement in there, ala:

enum SpanMode
{
    deep,
    wide,
    shallow,

    deprecated("Please use SpanMode.deep")
    depth = deep,

    deprecated("Please use SpanMode.wide")
    breadth = wide,
}
Comment 1 Andrej Mitrovic 2013-06-15 08:00:30 UTC
*** Issue 10362 has been marked as a duplicate of this issue. ***
Comment 2 Jonathan M Davis 2017-02-20 19:23:57 UTC
This would definitely be nice. I ran into this problem when working on bindings for Qt5. They have a number of enum members that they have added new names for and then marked the old ones as deprecated, and while most declarations in D can be marked as deprecated, the best that we can do here is say something in the documentation. Now, that's all that Qt can do either, since it's C++, but since pretty much any other declaration could be marked as deprecated in D, this restriction is annoying and arguably inconsistent.
Comment 3 Jan Jurzitza 2019-05-11 20:50:24 UTC
this has been added in DMD 2.082.0: https://dlang.org/changelog/2.082.0.html#enum_attributes