mirror of
https://github.com/ETLCPP/etl.git
synced 2026-10-28 18:07:10 +08:00
Fix make_array and make_deque rejecting const-qualified lvalues of the element type (#1526)
* Fixed make_array rejecting const-qualified lvalues of the element type make_array forwarded each argument as T (the element type) rather than as its own deduced type. etl::forward<T> accepts only a non-const T& or a T&&, and a T&& cannot bind to a reference-related const lvalue, so any call passing a const-qualified lvalue of type T failed to compile: static const char c = 42; etl::make_array<char>(c, c); // error: would lose const qualifier Arguments of *other* types slipped through via temporary materialisation, which is why the existing conversion and move tests never caught it. Forward each argument as its own deduced type and convert explicitly with static_cast<T>. The explicit conversion is required rather than plain forwarding: function parameters are not constant expressions, so narrowing initialisers such as make_array<char>(0, 1) - which the old code accepted and the tests cover - would otherwise be rejected by the braced initialiser list. Adds regression tests for const/non-const lvalues of the element type and for constexpr evaluation. Verified with clang 22 (C++14/17/20) and GCC 14 (C++11/20); existing conversion and move-only patterns still compile. * Fixed make_deque rejecting const-qualified lvalues of the element type make_deque had the same defect fixed for make_array in the previous commit: it forwarded each argument as T (the element type) rather than as its own deduced type. etl::forward<T> accepts only a non-const T& or a T&&, and a T&& cannot bind to a reference-related const lvalue, so any call passing a const-qualified lvalue of type T failed to compile: static const char c = 42; etl::make_deque<char>(c, c); // error: would lose const qualifier An audit of all other make_xxx container factories found no further instances - they forward each argument as its own deduced pack type, which is the correct idiom. Forward each argument as its own deduced type and convert explicitly with static_cast<T>. The explicit conversion keeps narrowing initialisers such as make_deque<char>(0, 1) - which the old code accepted and test_make_deque covers - working, which plain forwarding into the braced initialiser list would reject. Adds a regression test for const/non-const lvalues of the element type. No constexpr test, unlike make_array: etl::deque is not a literal type, so make_deque cannot be evaluated at compile time. Verified with clang 22 (C++14/17/20); the new test fails to compile before the fix and passes after, and all 101 deque tests pass. * Added narrowing-conversion regression tests for make_array and make_deque Review feedback on the make_deque fix: the const-lvalue regression test only passes arguments that already have the element type, so nothing exercises the static_cast<T> conversion that keeps narrowing initialisers working. If the implementation regressed to plain forwarding into the braced initialiser list, narrowing calls such as make_deque<char>(0, 1) would fail to compile. make_array already covered narrowing from int literals via test_make_array, but neither container covered conversion from const-qualified lvalues of a different type (const int narrowed to char), which combines both dimensions of the fix. Adds a matching test to each container covering int literals plus const/non-const int lvalues, all narrowed to char. Verified with clang 22 (C++17): 102 deque and 53 array tests pass. * Added const-lvalue regression tests for the remaining make_xxx factories Review feedback on the make_array/make_deque fixes asked whether the same defect - rejecting const-qualified lvalue arguments by forwarding each argument as the element type rather than as its own deduced type - exists in the other make_xxx container factories. The audit found that it does not: the other factories forward each argument as its own deduced pack type. These tests pin that down explicitly for every remaining factory, mirroring the make_array and make_deque regression tests: - make_vector, make_forward_list, make_indirect_vector (element type deduced via common_type): const/non-const char lvalues, element type checked. - make_set, make_multiset, make_flat_set, make_flat_multiset, make_unordered_set, make_unordered_multiset: const/non-const lvalues of the key type. - make_map, make_multimap, make_flat_map, make_flat_multimap, make_unordered_map, make_unordered_multimap: const/non-const lvalues of the pair type. make_reference_flat_* are excluded: they cannot currently be instantiated at all (no initializer_list constructor exists in the reference containers), which is reported separately. Verified with clang 22 (C++17): all 15 test suites pass (996 tests). * Added make_forward_list parity tests matching the make_list fixes Checked whether the make_list defect - taking its argument pack by value, costing an extra move per lvalue argument - also applies to make_forward_list. It does not: make_forward_list already takes its pack by forwarding reference, as make_vector does. No header change is needed. Adds the two tests that accompanied the make_list fix so that forward_list has the same coverage and the same regression detector: - test_make_forward_list_common_type_from_mixed_types, confirming the element type deduction through common_type. - test_make_forward_list_argument_copy_and_move_counts, an instrumented type counting copy/move constructions. This is the test that fails if the pack ever regresses to by-value (one extra move per lvalue argument). The exact move counts are C++17-only, as before C++17 the non-guaranteed return elision may add a move per element. Verified with clang 22 (C++17): all 67 forward_list tests pass. --------- Co-authored-by: Roland Reichwein <Roland.Reichwein@bmw.de>
This commit is contained in:
parent
3ff6ca1efc
commit
70d64496e6
@ -1056,7 +1056,13 @@ namespace etl
|
||||
template <typename T, typename... TValues>
|
||||
constexpr auto make_array(TValues&&... values) ETL_NOEXCEPT -> etl::array<T, sizeof...(TValues)>
|
||||
{
|
||||
return {etl::forward<T>(values)...};
|
||||
// Forward each argument as its own deduced type, then convert explicitly to T.
|
||||
// Forwarding as T (the old behaviour) made the call ill-formed for any const-qualified
|
||||
// lvalue of type T: forward<T> requires a non-const T&, and a T&& cannot bind to a
|
||||
// reference-related const lvalue. The explicit conversion also keeps narrowing
|
||||
// initialisers (e.g. make_array<char>(0, 1)) working, which plain forwarding into the
|
||||
// braced initialiser list would reject.
|
||||
return {static_cast<T>(etl::forward<TValues>(values))...};
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@ -2535,7 +2535,13 @@ namespace etl
|
||||
template <typename T, typename... TValues>
|
||||
constexpr auto make_deque(TValues&&... values) -> etl::deque<T, sizeof...(TValues)>
|
||||
{
|
||||
return {etl::forward<T>(values)...};
|
||||
// Forward each argument as its own deduced type, then convert explicitly to T.
|
||||
// Forwarding as T (the old behaviour) made the call ill-formed for any const-qualified
|
||||
// lvalue of type T: forward<T> requires a non-const T&, and a T&& cannot bind to a
|
||||
// reference-related const lvalue. The explicit conversion also keeps narrowing
|
||||
// initialisers (e.g. make_deque<char>(0, 1)) working, which plain forwarding into the
|
||||
// braced initialiser list would reject.
|
||||
return {static_cast<T>(etl::forward<TValues>(values))...};
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@ -950,6 +950,69 @@ namespace
|
||||
}
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
#if ETL_HAS_INITIALIZER_LIST
|
||||
// Arguments that are const-qualified lvalues of the element type used to be rejected:
|
||||
// the old implementation forwarded each argument as T, and forward<T> cannot accept a
|
||||
// const T lvalue (it requires a non-const T&, and T&& cannot bind to a reference-related
|
||||
// const lvalue).
|
||||
TEST(test_make_array_from_const_lvalues_of_element_type)
|
||||
{
|
||||
static const char static_const_lvalue = 42;
|
||||
const char local_const_lvalue = 43;
|
||||
char mutable_lvalue = 44;
|
||||
|
||||
auto data = etl::make_array<char>(static_const_lvalue, local_const_lvalue, mutable_lvalue);
|
||||
|
||||
using Type = etl::remove_reference_t<decltype(data[0])>;
|
||||
CHECK((std::is_same<char, Type>::value));
|
||||
|
||||
CHECK_EQUAL(42, data[0]);
|
||||
CHECK_EQUAL(43, data[1]);
|
||||
CHECK_EQUAL(44, data[2]);
|
||||
}
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
#if ETL_HAS_INITIALIZER_LIST
|
||||
// The arguments are converted to the element type with static_cast, so narrowing
|
||||
// initialisers (int literals and int lvalues narrowed to char) must keep working.
|
||||
// Plain forwarding into the braced initialiser list would reject them.
|
||||
TEST(test_make_array_from_narrowing_values)
|
||||
{
|
||||
static const int static_const_int = 45;
|
||||
const int local_const_int = 46;
|
||||
int mutable_int = 47;
|
||||
|
||||
auto data = etl::make_array<char>(0, 1, static_const_int, local_const_int, mutable_int);
|
||||
|
||||
using Type = etl::remove_reference_t<decltype(data[0])>;
|
||||
CHECK((std::is_same<char, Type>::value));
|
||||
|
||||
CHECK_EQUAL(0, data[0]);
|
||||
CHECK_EQUAL(1, data[1]);
|
||||
CHECK_EQUAL(45, data[2]);
|
||||
CHECK_EQUAL(46, data[3]);
|
||||
CHECK_EQUAL(47, data[4]);
|
||||
}
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
#if ETL_HAS_INITIALIZER_LIST && ETL_USING_CPP14
|
||||
TEST(test_make_array_is_constexpr)
|
||||
{
|
||||
static constexpr unsigned char constexpr_value = 0x18U;
|
||||
|
||||
constexpr auto data = etl::make_array<unsigned char>(constexpr_value, constexpr_value);
|
||||
|
||||
static_assert(data.size() == 2U, "make_array size");
|
||||
static_assert(data[0] == 0x18U, "make_array element");
|
||||
|
||||
CHECK_EQUAL(0x18U, data[0]);
|
||||
CHECK_EQUAL(0x18U, data[1]);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if ETL_USING_CPP14
|
||||
//*************************************************************************
|
||||
using Array = etl::array<int, 10U>;
|
||||
|
||||
@ -2299,6 +2299,53 @@ namespace
|
||||
}
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
#if ETL_USING_CPP11 && ETL_HAS_INITIALIZER_LIST
|
||||
// Arguments that are const-qualified lvalues of the element type used to be rejected:
|
||||
// the old implementation forwarded each argument as T, and forward<T> cannot accept a
|
||||
// const T lvalue (it requires a non-const T&, and T&& cannot bind to a reference-related
|
||||
// const lvalue).
|
||||
TEST(test_make_deque_from_const_lvalues_of_element_type)
|
||||
{
|
||||
static const char static_const_lvalue = 42;
|
||||
const char local_const_lvalue = 43;
|
||||
char mutable_lvalue = 44;
|
||||
|
||||
auto data = etl::make_deque<char>(static_const_lvalue, local_const_lvalue, mutable_lvalue);
|
||||
|
||||
using Type = etl::remove_reference_t<decltype(data[0])>;
|
||||
CHECK((std::is_same<char, Type>::value));
|
||||
|
||||
CHECK_EQUAL(42, data[0]);
|
||||
CHECK_EQUAL(43, data[1]);
|
||||
CHECK_EQUAL(44, data[2]);
|
||||
}
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
#if ETL_USING_CPP11 && ETL_HAS_INITIALIZER_LIST
|
||||
// The arguments are converted to the element type with static_cast, so narrowing
|
||||
// initialisers (int literals and int lvalues narrowed to char) must keep working.
|
||||
// Plain forwarding into the braced initialiser list would reject them.
|
||||
TEST(test_make_deque_from_narrowing_values)
|
||||
{
|
||||
static const int static_const_int = 45;
|
||||
const int local_const_int = 46;
|
||||
int mutable_int = 47;
|
||||
|
||||
auto data = etl::make_deque<char>(0, 1, static_const_int, local_const_int, mutable_int);
|
||||
|
||||
using Type = etl::remove_reference_t<decltype(data[0])>;
|
||||
CHECK((std::is_same<char, Type>::value));
|
||||
|
||||
CHECK_EQUAL(0, data[0]);
|
||||
CHECK_EQUAL(1, data[1]);
|
||||
CHECK_EQUAL(45, data[2]);
|
||||
CHECK_EQUAL(46, data[3]);
|
||||
CHECK_EQUAL(47, data[4]);
|
||||
}
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_fill)
|
||||
{
|
||||
|
||||
@ -1544,6 +1544,29 @@ namespace
|
||||
}
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
#if ETL_HAS_INITIALIZER_LIST
|
||||
// Arguments that are const-qualified lvalues of the pair type must be
|
||||
// accepted. Guards against the defect fixed for make_array and make_deque,
|
||||
// which forwarded each argument as the element type rather than as its own
|
||||
// deduced type and so rejected const lvalues.
|
||||
TEST_FIXTURE(SetupFixture, test_make_flat_map_from_const_lvalues_of_pair_type)
|
||||
{
|
||||
using Pair = ETL_OR_STD::pair<const char, int>;
|
||||
|
||||
static const Pair static_const_lvalue('a', 0);
|
||||
const Pair local_const_lvalue('b', 1);
|
||||
Pair mutable_lvalue('c', 2);
|
||||
|
||||
auto data = etl::make_flat_map<char, int>(static_const_lvalue, local_const_lvalue, mutable_lvalue);
|
||||
|
||||
CHECK_EQUAL(3U, data.size());
|
||||
CHECK_EQUAL(0, data.at('a'));
|
||||
CHECK_EQUAL(1, data.at('b'));
|
||||
CHECK_EQUAL(2, data.at('c'));
|
||||
}
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_contains)
|
||||
{
|
||||
|
||||
@ -1300,6 +1300,29 @@ namespace
|
||||
}
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
#if ETL_HAS_INITIALIZER_LIST
|
||||
// Arguments that are const-qualified lvalues of the pair type must be
|
||||
// accepted. Guards against the defect fixed for make_array and make_deque,
|
||||
// which forwarded each argument as the element type rather than as its own
|
||||
// deduced type and so rejected const lvalues.
|
||||
TEST_FIXTURE(SetupFixture, test_make_flat_multimap_from_const_lvalues_of_pair_type)
|
||||
{
|
||||
using Pair = ETL_OR_STD::pair<const char, int>;
|
||||
|
||||
static const Pair static_const_lvalue('a', 0);
|
||||
const Pair local_const_lvalue('b', 1);
|
||||
Pair mutable_lvalue('c', 2);
|
||||
|
||||
auto data = etl::make_flat_multimap<char, int>(static_const_lvalue, local_const_lvalue, mutable_lvalue);
|
||||
|
||||
CHECK_EQUAL(3U, data.size());
|
||||
CHECK_EQUAL(0, data.find('a')->second);
|
||||
CHECK_EQUAL(1, data.find('b')->second);
|
||||
CHECK_EQUAL(2, data.find('c')->second);
|
||||
}
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_contains)
|
||||
{
|
||||
|
||||
@ -1293,6 +1293,34 @@ namespace
|
||||
}
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
#if ETL_HAS_INITIALIZER_LIST
|
||||
// Arguments that are const-qualified lvalues of the key type must be
|
||||
// accepted. Guards against the defect fixed for make_array and make_deque,
|
||||
// which forwarded each argument as the element type rather than as its own
|
||||
// deduced type and so rejected const lvalues.
|
||||
TEST_FIXTURE(SetupFixture, test_make_flat_multiset_from_const_lvalues_of_key_type)
|
||||
{
|
||||
static const char static_const_lvalue = 42;
|
||||
const char local_const_lvalue = 43;
|
||||
char mutable_lvalue = 44;
|
||||
|
||||
auto data = etl::make_flat_multiset<char>(static_const_lvalue, local_const_lvalue, mutable_lvalue);
|
||||
|
||||
auto v = *data.begin();
|
||||
using Type = decltype(v);
|
||||
CHECK((std::is_same<char, Type>::value));
|
||||
|
||||
decltype(data)::const_iterator itr = data.begin();
|
||||
|
||||
CHECK_EQUAL(42, *itr);
|
||||
++itr;
|
||||
CHECK_EQUAL(43, *itr);
|
||||
++itr;
|
||||
CHECK_EQUAL(44, *itr);
|
||||
}
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_contains)
|
||||
{
|
||||
|
||||
@ -1292,6 +1292,34 @@ namespace
|
||||
}
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
#if ETL_HAS_INITIALIZER_LIST
|
||||
// Arguments that are const-qualified lvalues of the key type must be
|
||||
// accepted. Guards against the defect fixed for make_array and make_deque,
|
||||
// which forwarded each argument as the element type rather than as its own
|
||||
// deduced type and so rejected const lvalues.
|
||||
TEST_FIXTURE(SetupFixture, test_make_flat_set_from_const_lvalues_of_key_type)
|
||||
{
|
||||
static const char static_const_lvalue = 42;
|
||||
const char local_const_lvalue = 43;
|
||||
char mutable_lvalue = 44;
|
||||
|
||||
auto data = etl::make_flat_set<char>(static_const_lvalue, local_const_lvalue, mutable_lvalue);
|
||||
|
||||
auto v = *data.begin();
|
||||
using Type = decltype(v);
|
||||
CHECK((std::is_same<char, Type>::value));
|
||||
|
||||
decltype(data)::const_iterator itr = data.begin();
|
||||
|
||||
CHECK_EQUAL(42, *itr);
|
||||
++itr;
|
||||
CHECK_EQUAL(43, *itr);
|
||||
++itr;
|
||||
CHECK_EQUAL(44, *itr);
|
||||
}
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_contains)
|
||||
{
|
||||
|
||||
@ -1445,6 +1445,117 @@ namespace
|
||||
}
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
#if ETL_HAS_INITIALIZER_LIST
|
||||
// Arguments that are const-qualified lvalues must be accepted and must not
|
||||
// affect the deduced element type. Guards against the defect fixed for
|
||||
// make_array and make_deque, which forwarded each argument as the element
|
||||
// type rather than as its own deduced type and so rejected const lvalues.
|
||||
TEST(test_make_forward_list_from_const_lvalues_of_element_type)
|
||||
{
|
||||
static const char static_const_lvalue = 42;
|
||||
const char local_const_lvalue = 43;
|
||||
char mutable_lvalue = 44;
|
||||
|
||||
auto data = etl::make_forward_list(static_const_lvalue, local_const_lvalue, mutable_lvalue);
|
||||
|
||||
auto v = *data.begin();
|
||||
using Type = decltype(v);
|
||||
CHECK((std::is_same<char, Type>::value));
|
||||
|
||||
decltype(data)::const_iterator itr = data.begin();
|
||||
|
||||
CHECK_EQUAL(42, *itr++);
|
||||
CHECK_EQUAL(43, *itr++);
|
||||
CHECK_EQUAL(44, *itr++);
|
||||
}
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
#if ETL_HAS_INITIALIZER_LIST
|
||||
TEST(test_make_forward_list_common_type_from_mixed_types)
|
||||
{
|
||||
auto data = etl::make_forward_list(1, 2L, 3);
|
||||
|
||||
CHECK((std::is_same<etl::forward_list<long, 3U>, decltype(data)>::value));
|
||||
|
||||
auto itr = data.begin();
|
||||
CHECK_EQUAL(1L, *itr++);
|
||||
CHECK_EQUAL(2L, *itr++);
|
||||
CHECK_EQUAL(3L, *itr++);
|
||||
}
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
#if ETL_HAS_INITIALIZER_LIST
|
||||
struct CopyMoveCounted
|
||||
{
|
||||
explicit CopyMoveCounted(int value_)
|
||||
: value(value_)
|
||||
{
|
||||
}
|
||||
|
||||
CopyMoveCounted(const CopyMoveCounted& other)
|
||||
: value(other.value)
|
||||
{
|
||||
++copy_count;
|
||||
}
|
||||
|
||||
CopyMoveCounted(CopyMoveCounted&& other)
|
||||
: value(other.value)
|
||||
{
|
||||
++move_count;
|
||||
}
|
||||
|
||||
int value;
|
||||
|
||||
static size_t copy_count;
|
||||
static size_t move_count;
|
||||
};
|
||||
|
||||
size_t CopyMoveCounted::copy_count = 0;
|
||||
size_t CopyMoveCounted::move_count = 0;
|
||||
|
||||
// The arguments must be forwarded into the initializer list, not taken by
|
||||
// value: a by-value parameter pack would cost an extra move per argument
|
||||
// (the defect fixed for make_list). Each element is then copied from the
|
||||
// initializer_list backing array into its node, which is why lvalue
|
||||
// arguments count two copies.
|
||||
TEST(test_make_forward_list_argument_copy_and_move_counts)
|
||||
{
|
||||
const CopyMoveCounted const_lvalue(1);
|
||||
CopyMoveCounted mutable_lvalue(2);
|
||||
|
||||
CopyMoveCounted::copy_count = 0;
|
||||
CopyMoveCounted::move_count = 0;
|
||||
|
||||
auto data = etl::make_forward_list(const_lvalue, mutable_lvalue);
|
||||
|
||||
CHECK_EQUAL(4U, CopyMoveCounted::copy_count);
|
||||
#if ETL_USING_CPP17
|
||||
// The exact move counts rely on guaranteed copy elision. Before C++17 the
|
||||
// returned forward_list may be move-constructed once more, which moves each
|
||||
// element, so only the copy counts are checked there.
|
||||
CHECK_EQUAL(0U, CopyMoveCounted::move_count);
|
||||
#endif
|
||||
|
||||
CopyMoveCounted::copy_count = 0;
|
||||
CopyMoveCounted::move_count = 0;
|
||||
|
||||
auto data2 = etl::make_forward_list(CopyMoveCounted(3));
|
||||
|
||||
CHECK_EQUAL(1U, CopyMoveCounted::copy_count);
|
||||
#if ETL_USING_CPP17
|
||||
CHECK_EQUAL(1U, CopyMoveCounted::move_count);
|
||||
#endif
|
||||
|
||||
auto itr = data.begin();
|
||||
CHECK_EQUAL(1, (*itr++).value);
|
||||
CHECK_EQUAL(2, (*itr).value);
|
||||
CHECK_EQUAL(3, data2.begin()->value);
|
||||
}
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_forward_list_exception_types)
|
||||
{
|
||||
|
||||
@ -1621,5 +1621,28 @@ namespace
|
||||
|
||||
CHECK(std::equal(blank_data.begin(), blank_data.end(), data.begin()));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
#if ETL_USING_CPP11 && ETL_HAS_INITIALIZER_LIST
|
||||
// Arguments that are const-qualified lvalues must be accepted and must not
|
||||
// affect the deduced element type. Guards against the defect fixed for
|
||||
// make_array and make_deque, which forwarded each argument as the element
|
||||
// type rather than as its own deduced type and so rejected const lvalues.
|
||||
TEST(test_make_indirect_vector_from_const_lvalues_of_element_type)
|
||||
{
|
||||
static const char static_const_lvalue = 42;
|
||||
const char local_const_lvalue = 43;
|
||||
char mutable_lvalue = 44;
|
||||
|
||||
auto data = etl::make_indirect_vector(static_const_lvalue, local_const_lvalue, mutable_lvalue);
|
||||
|
||||
using Type = typename std::remove_reference<decltype(data[0])>::type;
|
||||
CHECK((std::is_same<char, Type>::value));
|
||||
|
||||
CHECK_EQUAL(42, data[0]);
|
||||
CHECK_EQUAL(43, data[1]);
|
||||
CHECK_EQUAL(44, data[2]);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
} // namespace
|
||||
|
||||
@ -1765,6 +1765,29 @@ namespace
|
||||
}
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
#if ETL_HAS_INITIALIZER_LIST
|
||||
// Arguments that are const-qualified lvalues of the pair type must be
|
||||
// accepted. Guards against the defect fixed for make_array and make_deque,
|
||||
// which forwarded each argument as the element type rather than as its own
|
||||
// deduced type and so rejected const lvalues.
|
||||
TEST_FIXTURE(SetupFixture, test_make_map_from_const_lvalues_of_pair_type)
|
||||
{
|
||||
using Pair = ETL_OR_STD::pair<const char, int>;
|
||||
|
||||
static const Pair static_const_lvalue('a', 0);
|
||||
const Pair local_const_lvalue('b', 1);
|
||||
Pair mutable_lvalue('c', 2);
|
||||
|
||||
auto data = etl::make_map<char, int>(static_const_lvalue, local_const_lvalue, mutable_lvalue);
|
||||
|
||||
CHECK_EQUAL(3U, data.size());
|
||||
CHECK_EQUAL(0, data.at('a'));
|
||||
CHECK_EQUAL(1, data.at('b'));
|
||||
CHECK_EQUAL(2, data.at('c'));
|
||||
}
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_contains)
|
||||
{
|
||||
|
||||
@ -1685,6 +1685,29 @@ namespace
|
||||
}
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
#if ETL_HAS_INITIALIZER_LIST
|
||||
// Arguments that are const-qualified lvalues of the pair type must be
|
||||
// accepted. Guards against the defect fixed for make_array and make_deque,
|
||||
// which forwarded each argument as the element type rather than as its own
|
||||
// deduced type and so rejected const lvalues.
|
||||
TEST_FIXTURE(SetupFixture, test_make_multimap_from_const_lvalues_of_pair_type)
|
||||
{
|
||||
using Pair = ETL_OR_STD::pair<const char, int>;
|
||||
|
||||
static const Pair static_const_lvalue('a', 0);
|
||||
const Pair local_const_lvalue('b', 1);
|
||||
Pair mutable_lvalue('c', 2);
|
||||
|
||||
auto data = etl::make_multimap<char, int>(static_const_lvalue, local_const_lvalue, mutable_lvalue);
|
||||
|
||||
CHECK_EQUAL(3U, data.size());
|
||||
CHECK_EQUAL(0, data.find('a')->second);
|
||||
CHECK_EQUAL(1, data.find('b')->second);
|
||||
CHECK_EQUAL(2, data.find('c')->second);
|
||||
}
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_contains_with_transparent_comparator)
|
||||
{
|
||||
|
||||
@ -1608,6 +1608,34 @@ namespace
|
||||
}
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
#if ETL_HAS_INITIALIZER_LIST
|
||||
// Arguments that are const-qualified lvalues of the key type must be
|
||||
// accepted. Guards against the defect fixed for make_array and make_deque,
|
||||
// which forwarded each argument as the element type rather than as its own
|
||||
// deduced type and so rejected const lvalues.
|
||||
TEST_FIXTURE(SetupFixture, test_make_multiset_from_const_lvalues_of_key_type)
|
||||
{
|
||||
static const char static_const_lvalue = 42;
|
||||
const char local_const_lvalue = 43;
|
||||
char mutable_lvalue = 44;
|
||||
|
||||
auto data = etl::make_multiset<char>(static_const_lvalue, local_const_lvalue, mutable_lvalue);
|
||||
|
||||
auto v = *data.begin();
|
||||
using Type = decltype(v);
|
||||
CHECK((std::is_same<char, Type>::value));
|
||||
|
||||
decltype(data)::const_iterator itr = data.begin();
|
||||
|
||||
CHECK_EQUAL(42, *itr);
|
||||
++itr;
|
||||
CHECK_EQUAL(43, *itr);
|
||||
++itr;
|
||||
CHECK_EQUAL(44, *itr);
|
||||
}
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_contains)
|
||||
{
|
||||
|
||||
@ -1465,6 +1465,34 @@ namespace
|
||||
}
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
#if ETL_HAS_INITIALIZER_LIST
|
||||
// Arguments that are const-qualified lvalues of the key type must be
|
||||
// accepted. Guards against the defect fixed for make_array and make_deque,
|
||||
// which forwarded each argument as the element type rather than as its own
|
||||
// deduced type and so rejected const lvalues.
|
||||
TEST_FIXTURE(SetupFixture, test_make_set_from_const_lvalues_of_key_type)
|
||||
{
|
||||
static const char static_const_lvalue = 42;
|
||||
const char local_const_lvalue = 43;
|
||||
char mutable_lvalue = 44;
|
||||
|
||||
auto data = etl::make_set<char>(static_const_lvalue, local_const_lvalue, mutable_lvalue);
|
||||
|
||||
auto v = *data.begin();
|
||||
using Type = decltype(v);
|
||||
CHECK((std::is_same<char, Type>::value));
|
||||
|
||||
decltype(data)::const_iterator itr = data.begin();
|
||||
|
||||
CHECK_EQUAL(42, *itr);
|
||||
++itr;
|
||||
CHECK_EQUAL(43, *itr);
|
||||
++itr;
|
||||
CHECK_EQUAL(44, *itr);
|
||||
}
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_contains)
|
||||
{
|
||||
|
||||
@ -1484,5 +1484,28 @@ namespace
|
||||
CHECK_TRUE(data.contains("FF"));
|
||||
CHECK_FALSE(data.contains(not_inserted));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
#if ETL_USING_CPP11 && ETL_HAS_INITIALIZER_LIST
|
||||
// Arguments that are const-qualified lvalues of the pair type must be
|
||||
// accepted. Guards against the defect fixed for make_array and make_deque,
|
||||
// which forwarded each argument as the element type rather than as its own
|
||||
// deduced type and so rejected const lvalues.
|
||||
TEST(test_make_unordered_map_from_const_lvalues_of_pair_type)
|
||||
{
|
||||
using Pair = ETL_OR_STD::pair<const char, int>;
|
||||
|
||||
static const Pair static_const_lvalue('a', 0);
|
||||
const Pair local_const_lvalue('b', 1);
|
||||
Pair mutable_lvalue('c', 2);
|
||||
|
||||
auto data = etl::make_unordered_map<char, int>(static_const_lvalue, local_const_lvalue, mutable_lvalue);
|
||||
|
||||
CHECK_EQUAL(3U, data.size());
|
||||
CHECK_EQUAL(0, data.at('a'));
|
||||
CHECK_EQUAL(1, data.at('b'));
|
||||
CHECK_EQUAL(2, data.at('c'));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
} // namespace
|
||||
|
||||
@ -1243,5 +1243,28 @@ namespace
|
||||
CHECK_TRUE(data.contains("FF"));
|
||||
CHECK_FALSE(data.contains(not_inserted));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
#if ETL_USING_CPP11 && ETL_HAS_INITIALIZER_LIST
|
||||
// Arguments that are const-qualified lvalues of the pair type must be
|
||||
// accepted. Guards against the defect fixed for make_array and make_deque,
|
||||
// which forwarded each argument as the element type rather than as its own
|
||||
// deduced type and so rejected const lvalues.
|
||||
TEST(test_make_unordered_multimap_from_const_lvalues_of_pair_type)
|
||||
{
|
||||
using Pair = ETL_OR_STD::pair<const char, int>;
|
||||
|
||||
static const Pair static_const_lvalue('a', 0);
|
||||
const Pair local_const_lvalue('b', 1);
|
||||
Pair mutable_lvalue('c', 2);
|
||||
|
||||
auto data = etl::make_unordered_multimap<char, int>(static_const_lvalue, local_const_lvalue, mutable_lvalue);
|
||||
|
||||
CHECK_EQUAL(3U, data.size());
|
||||
CHECK_EQUAL(0, data.find('a')->second);
|
||||
CHECK_EQUAL(1, data.find('b')->second);
|
||||
CHECK_EQUAL(2, data.find('c')->second);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
} // namespace
|
||||
|
||||
@ -1113,5 +1113,26 @@ namespace
|
||||
CHECK_TRUE(data.contains("FF"));
|
||||
CHECK_FALSE(data.contains(not_inserted));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
#if ETL_USING_CPP11 && ETL_HAS_INITIALIZER_LIST
|
||||
// Arguments that are const-qualified lvalues of the key type must be
|
||||
// accepted. Guards against the defect fixed for make_array and make_deque,
|
||||
// which forwarded each argument as the element type rather than as its own
|
||||
// deduced type and so rejected const lvalues.
|
||||
TEST(test_make_unordered_multiset_from_const_lvalues_of_key_type)
|
||||
{
|
||||
static const char static_const_lvalue = 42;
|
||||
const char local_const_lvalue = 43;
|
||||
char mutable_lvalue = 44;
|
||||
|
||||
auto data = etl::make_unordered_multiset<char>(static_const_lvalue, local_const_lvalue, mutable_lvalue);
|
||||
|
||||
CHECK_EQUAL(3U, data.size());
|
||||
CHECK_EQUAL(1U, data.count(42));
|
||||
CHECK_EQUAL(1U, data.count(43));
|
||||
CHECK_EQUAL(1U, data.count(44));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
} // namespace
|
||||
|
||||
@ -1122,6 +1122,27 @@ namespace
|
||||
CHECK_TRUE(data.contains("FF"));
|
||||
CHECK_FALSE(data.contains(not_inserted));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
#if ETL_USING_CPP11 && ETL_HAS_INITIALIZER_LIST
|
||||
// Arguments that are const-qualified lvalues of the key type must be
|
||||
// accepted. Guards against the defect fixed for make_array and make_deque,
|
||||
// which forwarded each argument as the element type rather than as its own
|
||||
// deduced type and so rejected const lvalues.
|
||||
TEST(test_make_unordered_set_from_const_lvalues_of_key_type)
|
||||
{
|
||||
static const char static_const_lvalue = 42;
|
||||
const char local_const_lvalue = 43;
|
||||
char mutable_lvalue = 44;
|
||||
|
||||
auto data = etl::make_unordered_set<char>(static_const_lvalue, local_const_lvalue, mutable_lvalue);
|
||||
|
||||
CHECK_EQUAL(3U, data.size());
|
||||
CHECK_EQUAL(1U, data.count(42));
|
||||
CHECK_EQUAL(1U, data.count(43));
|
||||
CHECK_EQUAL(1U, data.count(44));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#include "etl/private/diagnostic_pop.h"
|
||||
} // namespace
|
||||
|
||||
@ -1567,6 +1567,29 @@ namespace
|
||||
}
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
#if ETL_HAS_INITIALIZER_LIST
|
||||
// Arguments that are const-qualified lvalues must be accepted and must not
|
||||
// affect the deduced element type. Guards against the defect fixed for
|
||||
// make_array and make_deque, which forwarded each argument as the element
|
||||
// type rather than as its own deduced type and so rejected const lvalues.
|
||||
TEST(test_make_vector_from_const_lvalues_of_element_type)
|
||||
{
|
||||
static const char static_const_lvalue = 42;
|
||||
const char local_const_lvalue = 43;
|
||||
char mutable_lvalue = 44;
|
||||
|
||||
auto data = etl::make_vector(static_const_lvalue, local_const_lvalue, mutable_lvalue);
|
||||
|
||||
using Type = typename std::remove_reference<decltype(data[0])>::type;
|
||||
CHECK((std::is_same<char, Type>::value));
|
||||
|
||||
CHECK_EQUAL(42, data[0]);
|
||||
CHECK_EQUAL(43, data[1]);
|
||||
CHECK_EQUAL(44, data[2]);
|
||||
}
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_fill)
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user