[Issue 1594] version not honored for invarient declaration
John Mandeville
jemandy at earthlink.net
Fri Oct 19 12:07:06 PDT 2007
d-bugmail at puremagic.com Wrote:
> I know its not intuitive but the compiler is behaving correctly. All the code
> inside a version block must be valid code for the compiler you are using.
>
> Here is how you need to do what you want to achieve...
>
> version(D_Version2)
> {
> string str = "Version 2";
> mixin("invariant int myint = 2;");
> }
>
> else
> {
> string str = "Version 1";
> const int myint = 1;
> }
Hmmmm. The following would also work:
version (D_Version2)
{
mixin( "alias invariant int invarInt;" );
invarInt myint = 2;
}
Unfortunately, this does not work:
version (D_Version2)
{
mixin( "alias invariant int invarInt;" );
}
else
{
alias const int invarInt;
}
Neither v.1 nor v. 2 likes alias of const. (I can't figure out why neither likes alias of const but v. 2 likes alias of invariant. const is a storage class, not a type modifier; but then, I presume, the same is true for invariant in v. 2.)
Could an invariant storage class be added to version 1 that is just equivalent 10 const? We obviously don't want to add a new storage class semantics to version 1--changes to v. 1 at this point should be limited essentially to bug fixes. However, using the word invariant with const semantics might be a small enough change to be a worthwhile. It would be a convenience to those trying to develop for version 1 and version 2 sinultaneously.
More information about the Digitalmars-d-bugs
mailing list