custom attribute proposal (yeah, another one)

Adam D. Ruppe destructionator at gmail.com
Fri Apr 6 06:43:37 PDT 2012


On Friday, 6 April 2012 at 13:23:03 UTC, Steven Schveighoffer 
wrote:
> So here is my proposal:

This is a pretty good one. I can live with it.

Two notes though:

> 1. Introduce a new compiler-defined attribute @attribute (or 
> @attr or something better, the name isn't important).
> 2. This attribute can *only* be used on a module-level function.

This is a fine time to disallow built-in attribute identifiers.

safe is not a keyword:

int safe() { return 0; }
void main() { if(safe) assert(0); }

That's valid code.

But, @safe already has a meaning.

While int safe() is fine, @atttribute int safe() shouldn't
be.

If it throws an error when it sees that declaration, we're
in business.

@attribute int safe()
Error: attribute identifer safe is reserved for the compiler


> 3. @attribute functions *must* be CTFE-able.

Can this be statically checked? Since CTFE-able-ness
depends on runtime params and errors, I don't think so.

I'd say this should not be a strict requirement on
the declaration. Just let the CTFE fail when you try
to use it.



More information about the Digitalmars-d mailing list