47 Commits

Author SHA1 Message Date
rleigh-electradx
70d64496e6
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>
2026-08-17 10:13:34 +02:00
Roland Reichwein
04b7004110
Add emplace() to etl::map and further containers (#1462) 2026-06-20 10:57:06 +02:00
Christoph Rüthing
4f9618d8df
Make Constructors of Atomics for trivial Types constexpr (#1453)
* Bold project documentation link in README

* Add constexpr to trivial Atomics

According to https://en.cppreference.com/cpp/atomic/atomic/atomic the constructors of atomics should be constexpr. This change marks (at least for the trivial types) the constructor as constexpr.

---------

Co-authored-by: John Wellbelove <jwellbelove@users.noreply.github.com>
Co-authored-by: Roland Reichwein <Roland.Reichwein@bmw.de>
2026-06-08 15:23:35 +01:00
John Wellbelove
aeb8e4f734 Formatted source files 2026-04-02 14:11:45 +01:00
Roland Reichwein
b83cef5668
Fix compilation with -Wsign-conversion (#1367)
* Fix compilation with -Wsign-conversion

For tests with GCC and Clang

Fixes https://github.com/ETLCPP/etl/issues/632

* Fix support of negative Id in type_lookup.h: type_from_id

* Fix element access arithmetic in atomic_gcc_sync.h fetch_add/fetch_sub

* Fix rounded_integral_division.h: divide_round_half_odd(): direction is always 1
2026-03-28 11:15:56 +00:00
John Wellbelove
d884719098 Fixed all 'extra semicolon' warnings 2025-12-16 09:15:26 +00:00
John Wellbelove
191eaae225 Added transparent comparator overloads of contains() 2024-12-19 16:44:12 +00:00
John Wellbelove
1daa345038 Fix unused variables in test 2024-12-19 14:34:00 +00:00
John Wellbelove
784d95acaf Added additional transparent comparators to unordered containers 2024-12-19 14:33:59 +00:00
John Wellbelove
4a1712b733 #957 Support heterogenous lookup for maps 2024-12-19 14:30:14 +00:00
Aleksander Dejewski
602261ce39
Add contains() method to etl::unordered_map and etl::unordered_set (#990)
* Add contains() method to etl::unordered_map and etl::unordered_set

* Add contains() method to etl::unordered_multiset and etl::unordered_multimap

Use predefined variables in UT

Move contains() method to correct place in etl::unordered_set

* Fix contains() parameter type
2024-12-19 13:33:02 +00:00
John Wellbelove
489429bd7c Fixed operator == implementations 2023-12-13 09:58:44 +00:00
Soma Veszelovszki
93091cff0f Fixed: move assignment not working for non-empty containers (#759) 2023-09-20 23:06:32 +01:00
John Wellbelove
363a3e2dab Fix test array sizes
C++14 compiler compatibility

Updated test run scripts

Changed some ETL_ASSERT macros to ETL_ASSERT_OR_RETURN

Changed unit test macros for C++20 compaibility

Updated test run scripts

Updated CMake files to allow C++ standard selection

Replaced ETL_ASSERT_AND_RETURN with ETL_ASSERT_OR_RETURN

Updated C++14 & C++20 unit test compatibility

Changed native char8_t check

Added optional optimisation argument to bash script
2023-04-02 11:06:43 +01:00
Jesse Li
1b3d226547 Fix non-usage of key equal function (#606)
Co-authored-by: Jesse <jli@planarmotor.com>
2022-10-19 12:22:51 +01:00
John Wellbelove
c39ed5af80 Attempt to fix clang CI error 2022-09-12 00:00:06 +01:00
John Wellbelove
93aa08682c Attempt to fix clang CI error 2022-09-11 18:34:06 +01:00
John Wellbelove
15fd907549 Merge branch 'hotfix/#582-unordered_set-equality-comparison-fails-when-hash-collisions-occur' into development 2022-09-03 11:57:11 +01:00
John Wellbelove
eceaa23f47 #584 unordered_set::const_iterator has incorrect value_type 2022-09-03 11:56:24 +01:00
John Wellbelove
7c5a6e49a1 Fixed unordered container equality tests to match STL 2022-09-02 20:40:17 +01:00
John Wellbelove
4f5847e189 Updates for unordered maps and sets for an API that better matches the STL 2022-09-02 13:32:00 +01:00
John Wellbelove
cd18cc6af0 Eradicated all GCC and clang warnings 2022-07-27 10:42:03 +01:00
John Wellbelove
baa47d1c33 Updated copyright notice 2022-06-10 21:45:37 +01:00
John Wellbelove
9224df106e Fixed data alignment issues raised by sanitizer 2022-05-16 20:58:07 +01:00
John Wellbelove
740e490aed Tested ETL traits code. 2022-03-11 20:28:26 +00:00
John Wellbelove
343dabe7e2 Fixes for < GCC 8 2021-11-21 17:29:56 +00:00
John Wellbelove
8872b9a0ae const_iterator parameters for containers 2021-11-20 19:04:39 +00:00
CanastraRF
7c0f169b66
literal with suffix (#416) 2021-08-23 11:01:18 +01:00
John Wellbelove
dbfa71944f Abstracted unit test framework header 2021-03-05 13:52:34 +00:00
John Wellbelove
18d8236f91 Conditionally disable template deduction guide tests 2020-09-29 11:23:10 +01:00
John Wellbelove
509089c0e2 Added template deduction guides 2020-09-28 13:14:12 +01:00
John Wellbelove
f339e8d3da Fixed issue for incorrect operation of erase(const_iterator, const_iterator)
when the terminating iterator was end() for etl::unordered_map, etl::unordered_multimap, etl::unordered_set and etl::unordered_multiset.
2020-08-15 21:00:18 +01:00
John Wellbelove
e323f2267f Changed http://www.etlcpp.com to https://www.etlcpp.com 2020-05-01 10:22:36 +01:00
John Wellbelove
a108addf84 Added move API to unordered map and set containers.
Added a 'move' member function that moves items into the containers.
2020-03-30 18:05:33 +01:00
John Wellbelove
83347ccfdd Work in progress 2020-01-09 11:15:50 +00:00
John Wellbelove
94c5eed5a4 Work in progress 2020-01-04 11:49:22 +00:00
John Wellbelove
5803d928a1 Merge remote-tracking branch 'origin/feature/no_stl_unit_tests' into development
# Conflicts:
#	include/etl/stl/alternate/algorithm.h
#	include/etl/stl/alternate/iterator.h
#	include/etl/version.h
#	library.json
#	library.properties
#	support/Release notes.txt
#	test/test_no_stl_algorithm.cpp
#	test/test_no_stl_iterator.cpp
#	test/vs2017/etl.vcxproj
2019-12-01 18:21:10 +00:00
John Wellbelove
aee76d67e8 Merge remote-tracking branch 'origin/feature/bit_stream' into development
# Conflicts:
#	include/etl/profiles/armv6.h
#	include/etl/profiles/armv6_no_stl.h
#	include/etl/version.h
#	support/Release notes.txt
#	test/vs2017/etl.vcxproj.filters
2018-10-07 08:37:14 +01:00
John Wellbelove
bd008350a2 Merge remote-tracking branch 'origin/feature/changed_include_paths' into development
# Conflicts:
#	include/etl/version.h
2018-07-28 21:55:27 +01:00
John Wellbelove
eb222f54bb Containers are now deleteable through a pointer to their 'ixxxx' class. 2018-01-30 08:47:49 +00:00
John Wellbelove
c981bd0c96 Added emplace functions supporting up to four parameters to the following containers.
forward_list
list
vector
queue
priority_queue
stack

# Conflicts:
#	src/vector.h
#	test/data.h
#	test/vs2017/random.csv
2017-07-21 11:59:40 +01:00
John Wellbelove
26b7326d72 Updated Code::Blocks project.
Changed test project include paths to use unittest++ as sub-module.
2017-05-08 20:48:22 +01:00
John Wellbelove
aaac059008 Updated tests 2017-01-31 21:11:23 +00:00
John Wellbelove
6c4a29b498 Fixed bug in erase() 2016-12-30 11:56:08 +00:00
John Wellbelove
dd60c3aa7c Fixed GCC warnings 2016-12-28 12:57:04 +00:00
John Wellbelove
f1c5c20ba7 Changed folder structure to be compatible with Arduino library specifications 2016-02-28 14:04:22 +00:00
John Wellbelove
02aa427e6b Added unordered_set, unordered_multiset, unordered_multimap 2016-02-21 21:11:46 +00:00