[Issue 19174] New: Can't do conditional compiling with version attribute in enums

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Aug 17 06:55:40 UTC 2018


https://issues.dlang.org/show_bug.cgi?id=19174

          Issue ID: 19174
           Summary: Can't do conditional compiling with version attribute
                    in enums
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: blocker
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: zmxqaaev at abyssmail.com

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.

--


More information about the Digitalmars-d-bugs mailing list