static foreach @nogc

Timon Gehr timon.gehr at gmx.ch
Thu May 30 15:29:29 UTC 2019


On 30.05.19 17:02, Jacob Carlborg wrote:
> On 2019-05-30 04:56, Exil wrote:
>>
>> Am I missing something or should this be able to compile? I don't know 
>> where it is even using ~=, is it used internally for ranges?
>>
>> struct T
>> {
>> @nogc:
>>
>> auto opBinary(string op, V)(auto ref const(V) vec) const
>> {
>>      // Error: cannot use operator ~= in @nogc delegate 
>> onlineapp.T.opBinary!("+", T).opBinary.__lambda2
>>      static foreach(i ; 0 .. 1)
>>      {
>>      }
>>      return this;
>> }
>> }
>>
>> void main() {
>>      T a, b;
>>      T c = a + b;
>> }
>>
>>
>> https://run.dlang.io/is/JDXcJj
> 
> Looks like there are two issues here:
> 
> 1. That "static foreach" cannot be used in a @nogc function
> 2. That the error message mentions "delegate", which are not in the 
> source code
> 

The only issue here is that `@nogc:` applies to all nested functions, 
including delegates that are only used for CTFE.


More information about the Digitalmars-d mailing list