tberghammer requested changes to this revision.
tberghammer added a comment.
This revision now requires changes to proceed.

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:

- Gcc won't emit warnings because all code path have a return value.
- Clang will emit a warning if somebody adds a new data type without handling 
them in these GetAs{...} functions (this is why I don't want a default case).
- We have an additional runtime check for the fail case with the assert if the 
warnings are ignored.


http://reviews.llvm.org/D15355



_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to