[Lldb-commits] [PATCH] D55653: Check pointer results on nullptr before using them

Tatyana Krasnukha via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Thu Feb 14 12:41:24 PST 2019


tatyana-krasnukha added a comment.

Thanks for the review!



================
Comment at: MIDataTypes.h:67
+template <typename T>
+class MIDereferenceable {
+public:
----------------
shafik wrote:
> Can we use `llvm::Optional` instead? Then we can use `getValueOr()`.
Unfortunately no, with `Optional<T*>` getValueOr doesn't have the constraint that alternative value is not nullptr.
In case of `Optional<T>`  getValueOr returns T by value which is not what we need.


================
Comment at: MIDataTypes.h:71
+
+  T *Or(T &alt_value) { return m_ptr ? m_ptr : &alt_value; }
+private:
----------------
shafik wrote:
> If we can not use `llvm::Optional` then why not just take `T *`?
It is easier to read:

```
      const char *pFileName =
          GetDereferenceable(fileSpec.GetFilename()).Or(*pUnknown);
```
vs

```
      const char *pFileName = fileSpec.GetFilename();
      pFileName = (pFileName != nullptr) ? pFileName : pUnknown;
```
isn't it?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55653/new/

https://reviews.llvm.org/D55653





More information about the lldb-commits mailing list