Page MenuHomeFeedback Tracker

Method default arguments can't be OR'ed together
Assigned, NormalPublic

Description

When a method has default arguments that are OR'ed together, the resulting int will always be zero.

const int BAR_1 = 2;
const int BAR_2 = 4;

void Foo(int i = BAR_1 | BAR_2)
{
    PrintFormat("Foo %1", i);
}

Foo();

Result:
Foo 0

Details

Severity
None
Resolution
Open
Reproducibility
Always
Operating System
Windows 10 x64
Category
Modding

Event Timeline

lava76 created this task.Mar 16 2024, 12:09 PM

Default values are not evaluated, this has been an issue for as long as I can remember. It's not entirely useful for me, but I'll follow the ticket.

lava76 added a comment.EditedMar 17 2024, 8:40 PM

Oh they are evaluated, they just can't be OR'ed together. Using a single constant or enum works absolutely fine as default argument.

I.e. this is fine:

void Foo(int i = BAR_1)
{
    PrintFormat("Foo %1", i);
}

Foo();

Result:
Foo 2

Geez changed the task status from New to Assigned.Mar 18 2024, 10:08 AM