Bug 19174 – Can't do conditional compiling with version attribute in enums
Status
RESOLVED
Resolution
DUPLICATE
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2018-08-17T06:55:40Z
Last change time
2020-03-21T03:56:35Z
Assigned to
No Owner
Creator
D_Plz
Comments
Comment #0 by zmxqaaev — 2018-08-17T06:55:40Z
Example code:
version = 2;
//This doesn't compile
enum Test1 {
A = 1,
B,
version(2){
C = 4,
}
else version(1){
C
}
const D = C+1;
}
//This compiles, hack of above
struct TEST2 {
const A = 1;
const B = A+1;
version(2){
const C = B+2;
}
else version(1){
const C = B+1;
}
const D = C+1;
} __gshared TEST2 Test2;
void main()
{
import std.stdio;
writeln(Test1.D); //Doesn't work
writeln(Test2.D); //Example of desired behavior working
}
---------------------
Error log:
onlineapp.d(7): Error: basic type expected, not `version`
onlineapp.d(7): Error: no identifier for declarator `_error_`
onlineapp.d(7): Error: type only allowed if anonymous enum and no enum type
onlineapp.d(7): Error: if type, there must be an initializer
onlineapp.d(7): Error: found `version` when expecting `,`
onlineapp.d(7): Error: basic type expected, not `(`
onlineapp.d(7): Error: unexpected `(` in declarator
onlineapp.d(7): Error: basic type expected, not `2`
onlineapp.d(7): Error: found `2` when expecting `)`
onlineapp.d(7): Error: no identifier for declarator `_error_(_error_)`
onlineapp.d(7): Error: type only allowed if anonymous enum and no enum type
onlineapp.d(7): Error: if type, there must be an initializer
onlineapp.d(7): Error: found `)` when expecting `,`
onlineapp.d(7): Error: basic type expected, not `{`
onlineapp.d(7): Error: no identifier for declarator `_error_`
onlineapp.d(7): Error: type only allowed if anonymous enum and no enum type
onlineapp.d(7): Error: if type, there must be an initializer
onlineapp.d(7): Error: found `{` when expecting `,`
onlineapp.d(10): Error: declaration expected, not `else`
onlineapp.d(14): Error: unrecognized declaration
This is the same issue as Issue 9761 which was filed in 2013 and still listed as new with a changed severity from enhancement to blocker as this is a case of a feature that should work, as it does in similar other cases such as the struct example provided, being broken.
Comment #1 by b2.temp — 2019-11-24T10:28:06Z
*** This issue has been marked as a duplicate of issue 9761 ***