Frist Draft (in this forum): Enum Parameters

Paul Backus snarwin at gmail.com
Tue May 7 22:38:59 UTC 2024


On Tuesday, 7 May 2024 at 22:32:04 UTC, Meta wrote:
> On Tuesday, 7 May 2024 at 17:44:25 UTC, Paul Backus wrote:
>> If a single function in a call stack forgets to pass a given 
>> parameter by `ref`, it will be copied. If your code relies on 
>> the parameter not being copied (e.g., if it has a disabled 
>> copy constructor), this failure to preserve `ref` results in a 
>> bug.
>>
>> If a single function in a call stack forgets to pass a given 
>> parameter by `enum`, it will be evaluated at runtime. If your 
>> code relies on the parameter being evaluable at compile time 
>> (e.g., if it uses it as a template argument or in a `static 
>> if` condition), this failure to preserve `enum` results in a 
>> bug.
>
> Won't this always result in a compile error, not a runtime bug?

Yes. But in generic code, that compile error might not happen 
until a user instantiates it in a particular way that the library 
author hasn't thought of. (Again, see Phobos's handling of 
non-copyable types.)


More information about the dip.development mailing list