From 41174ed7f6eedc0be4bbfdebc021453af7785df7 Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Tue, 26 May 2026 05:18:27 +0200 Subject: [PATCH] Add missing constexpr to intrusive_links.h constructors (#1446) --- include/etl/intrusive_links.h | 16 ++++++------- test/test_intrusive_links.cpp | 42 +++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 8 deletions(-) diff --git a/include/etl/intrusive_links.h b/include/etl/intrusive_links.h index a1a9e653..3d23f326 100644 --- a/include/etl/intrusive_links.h +++ b/include/etl/intrusive_links.h @@ -91,25 +91,25 @@ namespace etl }; //*********************************** - forward_link() + ETL_CONSTEXPR forward_link() : etl_next(ETL_NULLPTR) { } //*********************************** - forward_link(forward_link* p_next) + ETL_CONSTEXPR forward_link(forward_link* p_next) : etl_next(p_next) { } //*********************************** - forward_link(const forward_link& other) + ETL_CONSTEXPR forward_link(const forward_link& other) : etl_next(other.etl_next) { } //*********************************** - forward_link& operator=(const forward_link& other) + ETL_CONSTEXPR14 forward_link& operator=(const forward_link& other) { etl_next = other.etl_next; @@ -495,28 +495,28 @@ namespace etl }; //*********************************** - bidirectional_link() + ETL_CONSTEXPR bidirectional_link() : etl_previous(ETL_NULLPTR) , etl_next(ETL_NULLPTR) { } //*********************************** - bidirectional_link(bidirectional_link* p_previous, bidirectional_link* p_next) + ETL_CONSTEXPR bidirectional_link(bidirectional_link* p_previous, bidirectional_link* p_next) : etl_previous(p_previous) , etl_next(p_next) { } //*********************************** - bidirectional_link(const bidirectional_link& other) + ETL_CONSTEXPR bidirectional_link(const bidirectional_link& other) : etl_previous(other.etl_previous) , etl_next(other.etl_next) { } //*********************************** - bidirectional_link& operator=(const bidirectional_link& other) + ETL_CONSTEXPR14 bidirectional_link& operator=(const bidirectional_link& other) { etl_previous = other.etl_previous; etl_next = other.etl_next; diff --git a/test/test_intrusive_links.cpp b/test/test_intrusive_links.cpp index 7bdbeb1b..141cb7f6 100644 --- a/test/test_intrusive_links.cpp +++ b/test/test_intrusive_links.cpp @@ -1855,5 +1855,47 @@ namespace // If we get here without crashing, the test passes CHECK(true); } + +#if ETL_USING_CPP14 + //************************************************************************* + TEST(test_forward_link_constexpr) + { + constexpr FLink0 link0{}; + static_assert(link0.etl_next == nullptr, "forward_link default ctor should be constexpr"); + + constexpr FLink0 link1{nullptr}; + static_assert(link1.etl_next == nullptr, "forward_link pointer ctor should be constexpr"); + + constexpr FLink0 link2{link1}; + static_assert(link2.etl_next == nullptr, "forward_link copy ctor should be constexpr"); + + CHECK(link0.etl_next == nullptr); + CHECK(link1.etl_next == nullptr); + CHECK(link2.etl_next == nullptr); + } + + //************************************************************************* + TEST(test_bidirectional_link_constexpr) + { + constexpr BLink0 link0{}; + static_assert(link0.etl_previous == nullptr, "bidirectional_link default ctor should be constexpr (previous)"); + static_assert(link0.etl_next == nullptr, "bidirectional_link default ctor should be constexpr (next)"); + + constexpr BLink0 link1{nullptr, nullptr}; + static_assert(link1.etl_previous == nullptr, "bidirectional_link param ctor should be constexpr (previous)"); + static_assert(link1.etl_next == nullptr, "bidirectional_link param ctor should be constexpr (next)"); + + constexpr BLink0 link2{link1}; + static_assert(link2.etl_previous == nullptr, "bidirectional_link copy ctor should be constexpr (previous)"); + static_assert(link2.etl_next == nullptr, "bidirectional_link copy ctor should be constexpr (next)"); + + CHECK(link0.etl_previous == nullptr); + CHECK(link0.etl_next == nullptr); + CHECK(link1.etl_previous == nullptr); + CHECK(link1.etl_next == nullptr); + CHECK(link2.etl_previous == nullptr); + CHECK(link2.etl_next == nullptr); + } +#endif } } // namespace