diff --git a/llvm/include/llvm/ADT/Optional.h b/llvm/include/llvm/ADT/Optional.h --- a/llvm/include/llvm/ADT/Optional.h +++ b/llvm/include/llvm/ADT/Optional.h @@ -43,7 +43,7 @@ public: ~OptionalStorage() { reset(); } - OptionalStorage() noexcept : empty(), hasVal(false) {} + constexpr OptionalStorage() noexcept : empty(), hasVal(false) {} OptionalStorage(OptionalStorage const &other) : OptionalStorage() { if (other.hasValue()) { @@ -148,7 +148,7 @@ public: ~OptionalStorage() = default; - OptionalStorage() noexcept : empty{} {} + constexpr OptionalStorage() noexcept : empty{} {} OptionalStorage(OptionalStorage const &other) = default; OptionalStorage(OptionalStorage &&other) = default; diff --git a/llvm/unittests/ADT/OptionalTest.cpp b/llvm/unittests/ADT/OptionalTest.cpp --- a/llvm/unittests/ADT/OptionalTest.cpp +++ b/llvm/unittests/ADT/OptionalTest.cpp @@ -17,6 +17,13 @@ using namespace llvm; +static_assert( + std::is_literal_type>::value, + "Optional should be usable in constexpr"); + +static_assert(std::is_literal_type>::value, + "Optional should be usable in constexpr"); + static_assert(is_trivially_copyable>::value, "trivially copyable");