Static assert triggered in struct constructor that shouldn't be called

jmh530 john.michael.hall at gmail.com
Sun May 24 22:06:06 UTC 2020


On Sunday, 24 May 2020 at 21:43:34 UTC, H. S. Teoh wrote:
> On Sun, May 24, 2020 at 09:34:53PM +0000, jmh530 via 
> Digitalmars-d-learn wrote:
>> The following code results in the static assert in the 
>> constructor being triggered, even though I would have thought 
>> no constructor would have been called. I know that there is an 
>> easy fix for this (move the static if outside the 
>> constructor), but it still seems like it doesn't make sense.
> [...]
>
> The problem is that static assert triggers when the function is 
> compiled (not when it's called), and since your ctor is not a 
> template function, it will always be compiled. Hence the static 
> assert will always trigger.
>
>
> T

Thanks. Makes sense.


More information about the Digitalmars-d-learn mailing list