www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Inconsistent attribute propagation?

reply Neia Neutuladh <neia ikeran.org> writes:
I noticed inconsistency with how builtin attributes propagate into types.

The following propagate to member functions:
*  safe
* const
* shared
* immutable
* linkage

The following do not:
* pure
*  nogc
* nothrow

Is this intentional? I'm not seeing anything in the spec about it.

Test code:

    import std.stdio;
    void main()
    {
        writeln(__traits(getFunctionAttributes, A.foo).stringof);
        writeln(__traits(getLinkage, A.foo));
    }
    
     safe  nogc pure const shared nothrow extern(C)
    struct A
    {
        void foo() {}
    }
Dec 01 2018
parent bauss <jj_1337 live.dk> writes:
On Saturday, 1 December 2018 at 18:09:39 UTC, Neia Neutuladh 
wrote:
 I noticed inconsistency with how builtin attributes propagate 
 into types.

 The following propagate to member functions:
 *  safe
 * const
 * shared
 * immutable
 * linkage

 The following do not:
 * pure
 *  nogc
 * nothrow

 Is this intentional? I'm not seeing anything in the spec about 
 it.

 Test code:

     import std.stdio;
     void main()
     {
         writeln(__traits(getFunctionAttributes, 
 A.foo).stringof);
         writeln(__traits(getLinkage, A.foo));
     }

      safe  nogc pure const shared nothrow extern(C)
     struct A
     {
         void foo() {}
     }
Not sure if intentional or not, but usual you'd do it like this: struct A { nogc: ... void foo() {} }
Dec 02 2018