[Issue 6415] Placement of pure and nothrow for invariant()

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Jun 9 18:19:13 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=6415



--- Comment #2 from Kenji Hara <k.hara.pg at gmail.com> 2013-06-09 18:19:12 PDT ---
(In reply to comment #0)
> This code shows a problem with placement of pure and nothrow:
> 
> class Foo {
>     pure nothrow invariant() {} // OK
>     invariant() pure nothrow {} // Error
> }
> void main() {}

Today `invariant {}` is parsed same as `immutable {}` (=
`AttributeDeclaration`), because in early D2 age `invariant` had been reused
for `immutable` meaning.
So `invariant` block requires following `()` to keep backward compatibility.
But, eventually the redundant parenthesis would be unnecessary, and you can
write invariant block as same as unittest block.

And, currently unittest block does not accept postfix attributes.

```d
invariant() @pure safe nothrow {}   // allwed by this change
invariant @pure safe nothrow {}     // eventually allowed?

unittest @pure safe nothrow {}      // currently not allowed
```

Therefore, just only fixing invariant syntax will introduce future
inconsistency. So we should consider unittest block syntax at the same time.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list