[Lldb-commits] [PATCH] D15355: Add failure paths to a few JSONNumber members

Tamas Berghammer via lldb-commits lldb-commits at lists.llvm.org
Wed Dec 9 02:41:55 PST 2015


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





More information about the lldb-commits mailing list