Skip to content

core: Avoid implicit Time conversions

I made a subtle error in a program due to an implicit conversion, and suggest a change to our Time APIs to prevent it.

Suppose I declare:

Time startTime = Seconds (2);

and then later, I intend to do:

Time appStartTime = startTime;

but I forget that startTime is a Time and not an integer or double, so I do:

Time appStartTime = Seconds (startTime);

This compiles and runs, but the value startTime is converted to an integer number of nanoseconds, so appStartTime actually gets the value 2e+9 seconds.

Attached patch prevents the implicit conversion of Time passed as value to these time methods.

Merge request reports