www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Position of unittest attributes

reply "Stefan Frijters" <sfrijters gmail.com> writes:
So I was trying to add some attributes to unittests in my code, 
but apparently they are only allowed *before* the unittest 
keyword, which I think makes it much harder to quickly see the 
unittests when scrolling through the code:

void foo()  safe pure nothrow  nogc { } // Ok - I normally use 
this style, and Phobos does too, I think?
 safe pure nothrow  nogc void bar() { } // Ok

 safe pure nothrow  nogc unittest { foo(); } // Ok
unittest  safe pure nothrow  nogc { bar(); } // Nope

I looked through the D grammar and it does seem to disallow this, 
so it's not a bug as such, but is there a particular reason to 
not allow it?
Mar 22 2015
parent reply Rikki Cattermole <alphaglosined gmail.com> writes:
On 22/03/2015 10:29 p.m., Stefan Frijters wrote:
 So I was trying to add some attributes to unittests in my code, but
 apparently they are only allowed *before* the unittest keyword, which I
 think makes it much harder to quickly see the unittests when scrolling
 through the code:

 void foo()  safe pure nothrow  nogc { } // Ok - I normally use this
 style, and Phobos does too, I think?
  safe pure nothrow  nogc void bar() { } // Ok

  safe pure nothrow  nogc unittest { foo(); } // Ok
 unittest  safe pure nothrow  nogc { bar(); } // Nope

 I looked through the D grammar and it does seem to disallow this, so
 it's not a bug as such, but is there a particular reason to not allow it?
Post attributes to e.g. functions are a relatively new standard in D. It'll simply be nobody has brought it up as of yet. File it into the issue tracker.
Mar 22 2015
parent "Stefan Frijters" <sfrijters gmail.com> writes:
On Sunday, 22 March 2015 at 09:42:44 UTC, Rikki Cattermole wrote:
 On 22/03/2015 10:29 p.m., Stefan Frijters wrote:
 So I was trying to add some attributes to unittests in my 
 code, but
 apparently they are only allowed *before* the unittest 
 keyword, which I
 think makes it much harder to quickly see the unittests when 
 scrolling
 through the code:

 void foo()  safe pure nothrow  nogc { } // Ok - I normally use 
 this
 style, and Phobos does too, I think?
  safe pure nothrow  nogc void bar() { } // Ok

  safe pure nothrow  nogc unittest { foo(); } // Ok
 unittest  safe pure nothrow  nogc { bar(); } // Nope

 I looked through the D grammar and it does seem to disallow 
 this, so
 it's not a bug as such, but is there a particular reason to 
 not allow it?
Post attributes to e.g. functions are a relatively new standard in D. It'll simply be nobody has brought it up as of yet. File it into the issue tracker.
Thank you. While filing in the summary field in Bugzilla it actually showed me an issue already exists https://issues.dlang.org/show_bug.cgi?id=10925 , so I just bumped it a bit.
Mar 22 2015