diff --git a/gdb/common/gdb_optional.h b/gdb/common/gdb_optional.h
index ad1119f..c30fa5b 100644
--- a/gdb/common/gdb_optional.h
+++ b/gdb/common/gdb_optional.h
@@ -20,46 +20,141 @@
 #ifndef GDB_OPTIONAL_H
 #define GDB_OPTIONAL_H
 
+#include "common/traits.h"
+
 namespace gdb
 {
 
+struct in_place_t
+{
+  explicit in_place_t () = default;
+};
+
+constexpr gdb::in_place_t in_place {};
+
 /* This class attempts to be a compatible subset of std::optional,
    which is slated to be available in C++17.  This class optionally
    holds an object of some type -- by default it is constructed not
    holding an object, but later the object can be "emplaced".  This is
    similar to using std::unique_ptr, but in-object allocation is
-   guaranteed.  */
+   guaranteed.
+
+   Unlike std::optional, we currently only support copy/move
+   construction/assignment of an optional<T> from either exactly
+   optional<T> or T.  I.e., we don't support copy/move
+   construction/assignment from optional<U> or U, when U is a type
+   convertible to T.  Making that work depending on the definitions of
+   T and U is somewhat complicated, and currently the users of this
+   class don't need it.  */
+
 template<typename T>
 class optional
 {
 public:
 
   constexpr optional ()
-    : m_dummy (),
-      m_instantiated (false)
+    : m_dummy ()
+  {}
+
+  template<typename... Args>
+  constexpr optional (in_place_t, Args &&... args)
+    : m_item (std::forward<Args> (args)...),
+      m_instantiated (true)
+  {}
+
+  ~optional ()
+  { this->reset (); }
+
+  /* Copy and move constructors.  */
+
+  optional (const optional &other)
   {
+    if (other.m_instantiated)
+      this->emplace (other.get ());
   }
 
-  ~optional ()
+  optional (optional &&other)
+    noexcept(std::is_nothrow_move_constructible<T> ())
+  {
+    if (other.m_instantiated)
+      this->emplace (std::move (other.get ()));
+  }
+
+  constexpr optional (const T &other)
+    : m_item (other),
+      m_instantiated (true)
+  {}
+
+  constexpr optional (T &&other)
+    noexcept (std::is_nothrow_move_constructible<T> ())
+    : m_item (std::move (other)),
+      m_instantiated (true)
+  {}
+
+  /* Assignment operators.  */
+
+  optional &
+  operator= (const optional &other)
+  {
+    if (m_instantiated && other.m_instantiated)
+      this->get () = other.get ();
+    else
+      {
+	if (other.m_instantiated)
+	  this->emplace (other.get ());
+	else
+	  this->reset ();
+      }
+
+    return *this;
+  }
+
+  optional &
+  operator= (optional &&other)
+    noexcept (And<std::is_nothrow_move_constructible<T>,
+	      std::is_nothrow_move_assignable<T>> ())
+  {
+    if (m_instantiated && other.m_instantiated)
+      this->get () = std::move (other.get ());
+    else
+      {
+	if (other.m_instantiated)
+	  this->emplace (std::move (other.get ()));
+	else
+	  this->reset ();
+      }
+    return *this;
+  }
+
+  optional &
+  operator= (const T &other)
   {
     if (m_instantiated)
-      destroy ();
+      this->get () = other;
+    else
+      this->emplace (other);
+    return *this;
   }
 
-  /* These aren't deleted in std::optional, but it was simpler to
-     delete them here, because currently the users of this class don't
-     need them, and making them depend on the definition of T is
-     somewhat complicated.  */
-  optional (const optional &other) = delete;
-  optional<T> &operator= (const optional &other) = delete;
+  optional &
+  operator= (T &&other)
+    noexcept (And<std::is_nothrow_move_constructible<T>,
+	      std::is_nothrow_move_assignable<T>> ())
+  {
+    if (m_instantiated)
+      this->get () = std::move (other);
+    else
+      this->emplace (std::move (other));
+    return *this;
+  }
 
   template<typename... Args>
-  void emplace (Args &&... args)
+  T &emplace (Args &&... args)
   {
-    if (m_instantiated)
-      destroy ();
+    this->reset ();
     new (&m_item) T (std::forward<Args>(args)...);
     m_instantiated = true;
+    return this->get ();
   }
 
   /* Observers.  */
@@ -87,6 +182,13 @@ public:
   constexpr bool has_value () const noexcept
   { return m_instantiated; }
 
+  /* 'reset' is a 'safe' operation with no precondition.  */
+  void reset () noexcept
+  {
+    if (m_instantiated)
+      this->destroy ();
+  }
+
 private:
 
   /* Destroy the object.  */
@@ -109,7 +211,7 @@ private:
   };
 
   /* True if the object was ever emplaced.  */
-  bool m_instantiated;
+  bool m_instantiated = false;
 };
 
 }
diff --git a/gdb/common/traits.h b/gdb/common/traits.h
index 4b7bac3..c8f29cc 100644
--- a/gdb/common/traits.h
+++ b/gdb/common/traits.h
@@ -18,6 +18,8 @@
 #ifndef COMMON_TRAITS_H
 #define COMMON_TRAITS_H
 
+#include <type_traits>
+
 namespace gdb {
 
 /* Pre C++14-safe (CWG 1558) version of C++17's std::void_t.  See
@@ -29,6 +31,30 @@ struct make_void { typedef void type; };
 template<typename... Ts>
 using void_t = typename make_void<Ts...>::type;
 
+/* A few trait helpers, mainly stolen from libstdc++.  Uppercase
+   because "and" is a keyword.  */
+
+template<typename...>
+struct And;
+
+template<>
+struct And<> : public std::true_type
+{};
+
+template<typename B1>
+struct And<B1> : public B1
+{};
+
+template<typename B1, typename B2>
+struct And<B1, B2>
+  : public std::conditional<B1::value, B2, B1>::type
+{};
+
+template<typename B1, typename B2, typename B3, typename... Bn>
+struct And<B1, B2, B3, Bn...>
+  : public std::conditional<B1::value, And<B2, B3, Bn...>, B1>::type
+{};
+
 }
 
 #endif /* COMMON_TRAITS_H */
