Skip to content

Commit d918429

Browse files
authored
Merge pull request #1673 from wilzbach/deprecate-enum-comparison
Deprecation: Issue 6227 - Comparison of different enums merged-on-behalf-of: Vladimir Panteleev <github@thecybershadow.net>
2 parents 842aad8 + 007c450 commit d918429

File tree

1 file changed

+39
-3
lines changed

1 file changed

+39
-3
lines changed

deprecate.dd

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ $(SPEC_S Deprecated Features,
1010

1111
$(TABLE2 Deprecated Features,
1212
$(THEAD Feature, Spec, Dep, Error, Gone)
13+
$(TROW $(DEPLINK Implicit comparison of different enums), 2.075, 2.075, &nbsp;, &nbsp;)
1314
$(TROW $(DEPLINK Implicit string concatenation), 2.072, 2.072, &nbsp;, &nbsp;)
1415
$(TROW $(DEPLINK Using the result of a comma expression), 2.072, 2.072, &nbsp;, &nbsp;)
1516
$(TROW $(DEPLINK delete), future, &nbsp;, &nbsp;, &nbsp;)
@@ -57,16 +58,51 @@ $(SPEC_S Deprecated Features,
5758
$(DD The feature is completely gone)
5859
)
5960

61+
$(H3 $(DEPNAME Implicit comparison of different enums))
62+
$(P Comparison of different enumerated type was allowed:
63+
---
64+
enum Status
65+
{
66+
good,
67+
bad
68+
}
69+
enum OtherStatus
70+
{
71+
ok
72+
no,
73+
}
74+
static assert(Status.good == OtherStatus.ok);
75+
---
76+
)
77+
$(H4 Corrective Action)
78+
$(P Comparison between unrelated enumerated types should be done with $(REF asOriginalType, std, conv))
79+
---
80+
import std.conv : asOriginalType;
81+
assert(Foo.x.asOriginalType == Bar.y.asOriginalType);
82+
---
83+
$(H4 Rationale)
84+
$(P Code correctness is improved by
85+
disallowing comparison of unrelated enumerated types. Implicit comparison of
86+
different `enum` types often resulted in hard to spot bugs.)
87+
88+
---
89+
enum { X }
90+
enum { Y }
91+
void main() {
92+
auto b = X == Y;
93+
assert(b);
94+
}
95+
---
6096

6197
$(H3 $(DEPNAME Implicit string concatenation))
62-
$(P Currently, two adjacent strings are implicitly concatenated:
98+
$(P Two adjacent strings were implicitly concatenated:
6399

64100
---
65101
string foo = "Hello" "World";
66102
---
67103

68-
This feature is handy for a long string that spans multiple lines,
69-
however it is possible to get the same behaviour explicitly by
104+
This feature was handy for a long string that spans multiple lines,
105+
however, it is possible to get the same behaviour explicitly by
70106
using the concatenation operator ('~'):
71107

72108
---

0 commit comments

Comments
 (0)