mirror of
https://github.com/TartanLlama/expected.git
synced 2025-08-03 19:04:29 +02:00
More constexpr fixes
This commit is contained in:
@@ -12,6 +12,7 @@ set(TEST_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/tests/main.cpp
|
|||||||
${CMAKE_CURRENT_SOURCE_DIR}/tests/extensions.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/tests/extensions.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/tests/assignment.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/tests/assignment.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/tests/emplace.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/tests/emplace.cpp
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/tests/issues.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/tests/bases.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/tests/bases.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/tests/observers.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/tests/observers.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/tests/constructors.cpp)
|
${CMAKE_CURRENT_SOURCE_DIR}/tests/constructors.cpp)
|
||||||
|
26
tests/issues.cpp
Normal file
26
tests/issues.cpp
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
#include "catch.hpp"
|
||||||
|
#include "expected.hpp"
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
using std::string;
|
||||||
|
|
||||||
|
tl::expected<int, string> getInt3(int val)
|
||||||
|
{
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
|
tl::expected<int, string> getInt2(int val)
|
||||||
|
{
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
|
tl::expected<int, string> getInt1()
|
||||||
|
{
|
||||||
|
return getInt2(5).and_then(getInt3);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TEST_CASE("Issue 1", "[issues.1]") {
|
||||||
|
getInt1();
|
||||||
|
}
|
@@ -375,7 +375,7 @@ template <class T, class E> struct expected_storage_base<T, E, true, true> {
|
|||||||
// T is trivial, E is not.
|
// T is trivial, E is not.
|
||||||
template <class T, class E> struct expected_storage_base<T, E, true, false> {
|
template <class T, class E> struct expected_storage_base<T, E, true, false> {
|
||||||
constexpr expected_storage_base() : m_val(T{}), m_has_val(true) {}
|
constexpr expected_storage_base() : m_val(T{}), m_has_val(true) {}
|
||||||
constexpr expected_storage_base(no_init_t) : m_has_val(false) {}
|
TL_EXPECTED_MSVC2015_CONSTEXPR expected_storage_base(no_init_t) : m_has_val(false) {}
|
||||||
|
|
||||||
template <class... Args,
|
template <class... Args,
|
||||||
detail::enable_if_t<std::is_constructible<T, Args &&...>::value> * =
|
detail::enable_if_t<std::is_constructible<T, Args &&...>::value> * =
|
||||||
@@ -1477,14 +1477,14 @@ public:
|
|||||||
class U = T,
|
class U = T,
|
||||||
detail::enable_if_t<!std::is_convertible<U &&, T>::value> * = nullptr,
|
detail::enable_if_t<!std::is_convertible<U &&, T>::value> * = nullptr,
|
||||||
detail::expected_enable_forward_value<T, E, U> * = nullptr>
|
detail::expected_enable_forward_value<T, E, U> * = nullptr>
|
||||||
explicit constexpr expected(U &&v) : expected(in_place, std::forward<U>(v)) {}
|
explicit TL_EXPECTED_MSVC2015_CONSTEXPR expected(U &&v) : expected(in_place, std::forward<U>(v)) {}
|
||||||
|
|
||||||
/// \exclude
|
/// \exclude
|
||||||
template <
|
template <
|
||||||
class U = T,
|
class U = T,
|
||||||
detail::enable_if_t<std::is_convertible<U &&, T>::value> * = nullptr,
|
detail::enable_if_t<std::is_convertible<U &&, T>::value> * = nullptr,
|
||||||
detail::expected_enable_forward_value<T, E, U> * = nullptr>
|
detail::expected_enable_forward_value<T, E, U> * = nullptr>
|
||||||
constexpr expected(U &&v) : expected(in_place, std::forward<U>(v)) {}
|
TL_EXPECTED_MSVC2015_CONSTEXPR expected(U &&v) : expected(in_place, std::forward<U>(v)) {}
|
||||||
|
|
||||||
template <
|
template <
|
||||||
class U = T,
|
class U = T,
|
||||||
|
Reference in New Issue
Block a user