Skip to content

Commit

Permalink
Revert change #804 to restore value initialisation of type0 for defau…
Browse files Browse the repository at this point in the history
…lt constructor
  • Loading branch information
John Wellbelove committed Apr 26, 2024
1 parent 5ab69e3 commit 76699fb
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 18 deletions.
10 changes: 8 additions & 2 deletions include/etl/private/variant_variadic.h
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,12 @@ namespace etl
constexpr bool operator <=(etl::monostate, etl::monostate) noexcept { return true; }
constexpr bool operator >=(etl::monostate, etl::monostate) noexcept { return true; }
constexpr bool operator ==(etl::monostate, etl::monostate) noexcept { return true; }
#if ETL_USING_CPP20 && ETL_USING_STL && !(defined(ETL_DEVELOPMENT_OS_APPLE) && defined(ETL_COMPILER_CLANG))
constexpr std::strong_ordering operator<=>(monostate, monostate) noexcept
{
return std::strong_ordering::equal;
}
#endif

#if ETL_NOT_USING_STL && !defined(ETL_USE_TYPE_TRAITS_BUILTINS)
template <>
Expand Down Expand Up @@ -532,7 +538,7 @@ namespace etl

default_construct_in_place<type>(data);
operation = operation_type<type, etl::is_copy_constructible<type>::value, etl::is_move_constructible<type>::value>::do_operation;
type_id = variant_npos;
type_id = 0U;
}
#include "diagnostic_pop.h"

Expand Down Expand Up @@ -1981,7 +1987,7 @@ namespace etl

namespace private_variant
{
#if ETL_USING_CPP20 && ETL_USING_STL
#if ETL_USING_CPP20 && ETL_USING_STL && !(defined(ETL_DEVELOPMENT_OS_APPLE) && defined(ETL_COMPILER_CLANG))
//***************************************************************************
/// C++20 compatible visitor function for testing variant '<=>'.
/// Assumes that the two variants are already known to contain the same type.
Expand Down
2 changes: 1 addition & 1 deletion include/etl/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ SOFTWARE.

#define ETL_VERSION_MAJOR 20
#define ETL_VERSION_MINOR 38
#define ETL_VERSION_PATCH 12
#define ETL_VERSION_PATCH 13

#define ETL_VERSION ETL_STRING(ETL_VERSION_MAJOR) "." ETL_STRING(ETL_VERSION_MINOR) "." ETL_STRING(ETL_VERSION_PATCH)
#define ETL_VERSION_W ETL_WIDE_STRING(ETL_VERSION_MAJOR) L"." ETL_WIDE_STRING(ETL_VERSION_MINOR) L"." ETL_WIDE_STRING(ETL_VERSION_PATCH)
Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Embedded Template Library",
"version": "20.38.12",
"version": "20.38.13",
"authors": {
"name": "John Wellbelove",
"email": "[email protected]"
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=Embedded Template Library
version=20.38.12
version=20.38.13
author= John Wellbelove <[email protected]>
maintainer=John Wellbelove <[email protected]>
license=MIT
Expand Down
37 changes: 25 additions & 12 deletions test/test_variant_variadic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,22 +446,35 @@ namespace
//*************************************************************************
TEST(test_constructor_default)
{
CHECK_NO_THROW(test_variant_etl_3 variant_etl);
struct DefaultConstructible
{
DefaultConstructible()
: value(1)
{
}

test_variant_etl_3 variant_etl;
int value = 0;
};

using test_variant_t = etl::variant<DefaultConstructible, int, std::string>;

CHECK_NO_THROW(test_variant_t variant_etl);

test_variant_t variant_etl;

CHECK(!etl::holds_alternative<char>(variant_etl));
CHECK(!etl::holds_alternative<int>(variant_etl));
CHECK(!etl::holds_alternative<std::string>(variant_etl));
CHECK_TRUE(etl::holds_alternative<DefaultConstructible>(variant_etl));
CHECK_FALSE(etl::holds_alternative<int>(variant_etl));
CHECK_FALSE(etl::holds_alternative<std::string>(variant_etl));
CHECK_EQUAL(1, etl::get<0U>(variant_etl).value);

CHECK(!etl::holds_alternative<0U>(variant_etl));
CHECK(!etl::holds_alternative<1U>(variant_etl));
CHECK(!etl::holds_alternative<2U>(variant_etl));
CHECK_TRUE(etl::holds_alternative<0U>(variant_etl));
CHECK_FALSE(etl::holds_alternative<1U>(variant_etl));
CHECK_FALSE(etl::holds_alternative<2U>(variant_etl));

CHECK(!etl::holds_alternative(0U, variant_etl));
CHECK(!etl::holds_alternative(1U, variant_etl));
CHECK(!etl::holds_alternative(2U, variant_etl));
CHECK(!etl::holds_alternative(99U, variant_etl));
CHECK_TRUE(etl::holds_alternative(0U, variant_etl));
CHECK_FALSE(etl::holds_alternative(1U, variant_etl));
CHECK_FALSE(etl::holds_alternative(2U, variant_etl));
CHECK_FALSE(etl::holds_alternative(99U, variant_etl));
}

//*************************************************************************
Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20.38.12
20.38.13

0 comments on commit 76699fb

Please sign in to comment.