diff --git a/common/copyable_unique_ptr.h b/common/copyable_unique_ptr.h index 05d3675b112f..9560deead546 100644 --- a/common/copyable_unique_ptr.h +++ b/common/copyable_unique_ptr.h @@ -175,7 +175,7 @@ class copyable_unique_ptr : public std::unique_ptr { heap-allocated copy of the source object, created using its copy constructor or `Clone()` method. The currently-held object (if any) is deleted. */ - copyable_unique_ptr & operator=(const T& ref) { + copyable_unique_ptr& operator=(const T& ref) { std::unique_ptr::reset(CopyOrNull(&ref)); return *this; } @@ -318,7 +318,10 @@ class copyable_unique_ptr : public std::unique_ptr { shore up this gap in the const correctness protection. @pre `this != nullptr` reports `true`. */ - const T& operator*() const { return *get(); } + const T& operator*() const { + DRAKE_ASSERT(!empty()); + return *get(); + } /** Return a writable reference to the contained object (if T is itself not const). Note that you need write access to this container in order to get @@ -336,7 +339,10 @@ class copyable_unique_ptr : public std::unique_ptr { reference. @pre `this != nullptr` reports `true`. */ - T& operator*() { return *get_mutable(); } + T& operator*() { + DRAKE_ASSERT(!empty()); + return *get_mutable(); + } /**@}*/ private: