Author: marshall Date: Wed May 17 10:30:01 2017 New Revision: 303268 URL: http://llvm.org/viewvc/llvm-project?rev=303268&view=rev Log: Mark the copy constructor and move constructor to be constexpr. This only works when the contained type has a constexpr copy/move ctor.
Modified: libcxx/trunk/include/optional libcxx/trunk/test/std/utilities/optional/optional.object/optional.object.ctor/copy.pass.cpp libcxx/trunk/test/std/utilities/optional/optional.object/optional.object.ctor/move.pass.cpp Modified: libcxx/trunk/include/optional URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/optional?rev=303268&r1=303267&r2=303268&view=diff ============================================================================== --- libcxx/trunk/include/optional (original) +++ libcxx/trunk/include/optional Wed May 17 10:30:01 2017 @@ -599,8 +599,8 @@ private: public: _LIBCPP_INLINE_VISIBILITY constexpr optional() noexcept {} - _LIBCPP_INLINE_VISIBILITY optional(const optional&) = default; - _LIBCPP_INLINE_VISIBILITY optional(optional&&) = default; + _LIBCPP_INLINE_VISIBILITY constexpr optional(const optional&) = default; + _LIBCPP_INLINE_VISIBILITY constexpr optional(optional&&) = default; _LIBCPP_INLINE_VISIBILITY constexpr optional(nullopt_t) noexcept {} template <class... _Args, class = enable_if_t< Modified: libcxx/trunk/test/std/utilities/optional/optional.object/optional.object.ctor/copy.pass.cpp URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/optional/optional.object/optional.object.ctor/copy.pass.cpp?rev=303268&r1=303267&r2=303268&view=diff ============================================================================== --- libcxx/trunk/test/std/utilities/optional/optional.object/optional.object.ctor/copy.pass.cpp (original) +++ libcxx/trunk/test/std/utilities/optional/optional.object/optional.object.ctor/copy.pass.cpp Wed May 17 10:30:01 2017 @@ -10,7 +10,7 @@ // UNSUPPORTED: c++98, c++03, c++11, c++14 // <optional> -// optional(const optional<T>& rhs); +// constexpr optional(const optional<T>& rhs); #include <optional> #include <type_traits> @@ -152,4 +152,9 @@ int main() { test_reference_extension(); } + { + constexpr std::optional<int> o1{4}; + constexpr std::optional<int> o2 = o1; + static_assert( *o2 == 4, "" ); + } } Modified: libcxx/trunk/test/std/utilities/optional/optional.object/optional.object.ctor/move.pass.cpp URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/optional/optional.object/optional.object.ctor/move.pass.cpp?rev=303268&r1=303267&r2=303268&view=diff ============================================================================== --- libcxx/trunk/test/std/utilities/optional/optional.object/optional.object.ctor/move.pass.cpp (original) +++ libcxx/trunk/test/std/utilities/optional/optional.object/optional.object.ctor/move.pass.cpp Wed May 17 10:30:01 2017 @@ -18,7 +18,7 @@ // <optional> -// optional(optional<T>&& rhs); +// constexpr optional(optional<T>&& rhs); #include <optional> #include <type_traits> @@ -206,4 +206,9 @@ int main() { test_reference_extension(); } + { + constexpr std::optional<int> o1{4}; + constexpr std::optional<int> o2 = std::move(o1); + static_assert( *o2 == 4, "" ); + } } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits