Add missing constexpr to intrusive_links.h constructors (#1446)

This commit is contained in:
Roland Reichwein 2026-05-26 05:18:27 +02:00 committed by GitHub
parent 6bb9841dae
commit 41174ed7f6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 50 additions and 8 deletions

View File

@ -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;

View File

@ -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