This patch updates GetAsUnsigned(), GetAsSigned(), and GetAsDouble() JSONNumber functions to add failure check.
The previous code was generating compiler warnings for not being able to provide a return path for all possibilities.
Differential D15355
Add failure paths to a few JSONNumber members omjavaid on Dec 8 2015, 3:05 PM. Authored by
Details This patch updates GetAsUnsigned(), GetAsSigned(), and GetAsDouble() JSONNumber functions to add failure check. The previous code was generating compiler warnings for not being able to provide a return path for all possibilities.
Diff Detail
Event TimelineComment Actions These GetAs{...} functions should never fail in their current implementation as we have only 3 different data type and all of them are handled. The new function signatures you proposed are making the API significantly harder to use with no benefit. (Also they will produce clang warnings because of the default in a switch covering all cases.) To silent the warning I would suggest to do this: double JSONNumber::GetAsDouble() const { switch (m_data_type) { case DataType::Unsigned: return (double)m_data.m_unsigned; case DataType::Signed: return (double)m_data.m_signed; case DataType::Double: return m_data.m_double; } assert(false && "Unhandled data type"); return 0; } In this code:
Comment Actions I don't know what correction you are referring to as I haven't made any change in JSON.{h,cpp} since you created this patch but I am happy with the current situation (no warning on clang) Comment Actions Sorry @tberghammer there was corruption in my setup showing changes which i just made internally. I have updated this diff as per suggestions. LGTM? |