Code:
int CCalendarSettingsGooglePage::GetReminderIntervalAsMinutes(int iReminderUnitType, int iReminderInterval) noexcept
{
int iMinutes = 24 * 60; // DEfault
if (iReminderUnitType == ReminderUnitType::Weeks)
iMinutes = iReminderInterval * 7 * 24 * 60;
else if (iReminderUnitType == ReminderUnitType::Days)
iMinutes = iReminderInterval * 24 * 60;
else if (iReminderUnitType == ReminderUnitType::Hours)
iMinutes = iReminderInterval * 60;
else if (iReminderUnitType == ReminderUnitType::Minutes)
iMinutes = iReminderInterval;
return iMinutes;
}
Analysis warning:
C26497 You can attempt to make
CCalendarSettingsGooglePage::GetReminderIntervalAsMinutes
constexpr
unless it contains any undefined behavior (f.4).
According to here (about constexpr
functions it does state:
The following rules apply to
constexpr
functions in Visual Studio 2017 and later:
- It may contain
if
andswitch
statements, and all looping statements includingfor
, range-basedfor
,while
, anddo-while
.
But the original warning does say unless it contains any undefined behavior. How do we confirm if it has undefined behaviour? I do not think so, but did not want to blindly turn it into a constexpr
function.