Thread overview
Class attributes
Oct 02, 2016
Satoshi
Oct 02, 2016
Basile B.
Oct 03, 2016
Satoshi
October 02, 2016
Hello,

why
pure @safe nothrow @nogc struct Point {
}

isn't same as

struct Point {
pure: @safe: nothrow: @nogc:
}

??
October 02, 2016
On Sunday, 2 October 2016 at 15:54:38 UTC, Satoshi wrote:
> Hello,
>
> why
> pure @safe nothrow @nogc struct Point {
> }
>
> isn't same as
>
> struct Point {
> pure: @safe: nothrow: @nogc:
> }
>
> ??

This is not specified but attributes aren't applied to the scope created by the declaration. Which is a good thing, for example with the visibility attributes it would be a problem, imagine the following declarations:

struct Foo(T)
{
    private struct Range // imagine that private as a inner "private:"
    {
        void popFront(); // would be private !!
        bool empty(); // would be private !!
        T front(); // would be private !!
    }
}

So this is really not something anyone would want.
October 03, 2016
On Sunday, 2 October 2016 at 17:22:57 UTC, Basile B. wrote:
> On Sunday, 2 October 2016 at 15:54:38 UTC, Satoshi wrote:
>> Hello,
>>
>> why
>> pure @safe nothrow @nogc struct Point {
>> }
>>
>> isn't same as
>>
>> struct Point {
>> pure: @safe: nothrow: @nogc:
>> }
>>
>> ??
>
> This is not specified but attributes aren't applied to the scope created by the declaration. Which is a good thing, for example with the visibility attributes it would be a problem, imagine the following declarations:
>
> struct Foo(T)
> {
>     private struct Range // imagine that private as a inner "private:"
>     {
>         void popFront(); // would be private !!
>         bool empty(); // would be private !!
>         T front(); // would be private !!
>     }
> }
>
> So this is really not something anyone would want.

But shared or abstract attribute can be applied to scope created by class so nothrow @safe @nogc or pure should be too.


It should follow same rules as in function declaration.

void test() @safe {
  void thisFunctionIsSafeToo() {

  }
}