D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 19174 - Can't do conditional compiling with version attribute in enums
Summary: Can't do conditional compiling with version attribute in enums
Status: RESOLVED DUPLICATE of issue 9761
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 enhancement
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-08-17 06:55 UTC by D_Plz
Modified: 2020-03-21 03:56 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description D_Plz 2018-08-17 06:55:40 UTC
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 basile-z 2019-11-24 10:28:06 UTC

*** This issue has been marked as a duplicate of issue 9761 ***