A code example that shows why I don't like warnings

Alexandru Ermicioi alexandru.ermicioi at gmail.com
Fri Oct 18 18:19:55 UTC 2019


On Friday, 18 October 2019 at 16:46:36 UTC, Adam D. Ruppe wrote:
> On Friday, 18 October 2019 at 16:43:54 UTC, FeepingCreature 
> wrote:
>> This does **not** spark joy. But it works.
>
> Yes, I just put in a runtime condition to trick the compiler:
>
> bool isScriptable(attributes...)() {
>         bool 
> nonConstConditionForWorkingAroundASpuriousDmdWarning = true;
>         foreach(attribute; attributes) {
>                 static if(is(typeof(attribute) == string)) {
>                         static if(attribute == scriptable) {
>                                 
> if(nonConstConditionForWorkingAroundASpuriousDmdWarning)
>                                 return true;
>                         }
>                 }
>         }
>         return false;
> }
>
>
> the optimizer can prolly remove that condition anyway but it is 
> good enough to silence the warning. still just all the work 
> arounds are kinda gross.

You can define a bool enum in the body of static if (inside 
foreach)  and then wrap default return statement with static if 
that checks if that enum was defined. If it wasn't then return 
"default".


More information about the Digitalmars-d mailing list