DIP 1029---Add throw as Function Attribute---Community Review Round 1

Dennis dkorpel at gmail.com
Tue Jan 14 21:22:17 UTC 2020

On Tuesday, 14 January 2020 at 10:44:17 UTC, Mike Parker wrote:
> #DIP1029
> #throw

First of all thanks for adding the section with a grammar diff 
and adding it to FunctionAttribute. I forgot to mention during 
draft review it should probably be added to StorageClass as well:

Otherwise it can't appear in an AutoFunctionDeclaration unlike 
void main() {
     nothrow foo() {} // currently allowed
     throw foo() {} // not allowed after this DIP because `throw` 
is no `StorageClass`

However, adding it to StorageClass adds an ambiguity:

void foo()() {
     nothrow bar(); // allowed according to grammar spec
     throw bar(); // throw statement or function declaration?

Now it should be noted that dmd doesn't actually parse that. I 
opened an issue for that:


That could make the problem away in this case, but I think the 
DIP should consider possible ambiguities like that that might be 

Further feedback:

- I still think that other attributes should be considered for 
this DIP. As I mentioned during draft review:

> pure isn't fortunate enough to have an opposite keyword for it. 
> If we end up going with e.g. pure(false) or !pure, then you'll 
> end up with either inconsistently not allowing nothrow(false) 
> or !nothrow, or multiple ways to specify a throw function.

It would be annoying to users if soon after the introduction of 
`throw` as a function attribute it would be phased out because a 
new consistent mechanism is introduced for all function 

On the other hand, adding an option to negate the nothrow 
attribute in the short term is welcome, and it can still be kept 
around with little harm even if it gets superceded.

- I still think it should be stated how the new attribute 
interacts with __traits(getFunctionAttributes):
void t0() nothrow; // tuple("nothrow", "@system")
void t1() throw; // tuple("throw", "@system")
void t2(); // tuple("@system") or tuple("throw", "@system")?

More information about the Digitalmars-d mailing list