[PATCH] D86354: [ADT] Make Optional a literal type.
Varun Gandhi via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 21 08:45:42 PDT 2020
varungandhi-apple created this revision.
varungandhi-apple added a reviewer: fhahn.
Herald added subscribers: llvm-commits, dexonsmith.
Herald added a project: LLVM.
varungandhi-apple requested review of this revision.
This allows returning Optional values from constexpr contexts.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D86354
Files:
llvm/include/llvm/ADT/Optional.h
llvm/unittests/ADT/OptionalTest.cpp
Index: llvm/unittests/ADT/OptionalTest.cpp
===================================================================
--- llvm/unittests/ADT/OptionalTest.cpp
+++ llvm/unittests/ADT/OptionalTest.cpp
@@ -17,6 +17,13 @@
using namespace llvm;
+static_assert(
+ std::is_literal_type<optional_detail::OptionalStorage<int>>::value,
+ "Optional should be usable in constexpr");
+
+static_assert(std::is_literal_type<Optional<int>>::value,
+ "Optional should be usable in constexpr");
+
static_assert(is_trivially_copyable<Optional<int>>::value,
"trivially copyable");
Index: llvm/include/llvm/ADT/Optional.h
===================================================================
--- llvm/include/llvm/ADT/Optional.h
+++ 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;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D86354.287044.patch
Type: text/x-patch
Size: 1342 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200821/2364ef6d/attachment.bin>
More information about the llvm-commits
mailing list