Array bounds and maybe-uninitialized warning fixes

This commit is contained in:
John Wellbelove 2023-02-28 18:33:49 +00:00
parent 16abc0cab4
commit 8ddf0935d3
26 changed files with 2058 additions and 1143 deletions

1
.gitignore vendored
View File

@ -368,3 +368,4 @@ test/vs2022/random_lsfr.csv
test/vs2022/random_mwc.csv
test/vs2022/random_pcg.csv
test/vs2022/random_xorshift.csv
test/vs2019/MSVC - No STL -O2

View File

@ -116,6 +116,11 @@ namespace etl
{
struct type
{
//type()
// : data()
//{
//}
/// Convert to T reference.
template <typename T>
operator T& ()

View File

@ -54,6 +54,7 @@ namespace etl
//*************************************************************************
/// Constructor.
//*************************************************************************
ETL_CONSTEXPR
exception(string_type reason_, string_type file_, numeric_type line_)
: reason_text(reason_),
file_text(file_),
@ -64,6 +65,7 @@ namespace etl
//*************************************************************************
/// Constructor.
//*************************************************************************
ETL_CONSTEXPR
exception(string_type reason_, string_type file_, numeric_type line_)
: reason_text(reason_),
line(line_)
@ -76,6 +78,7 @@ namespace etl
/// Gets the reason for the exception.
/// \return const char* to the reason.
//***************************************************************************
ETL_CONSTEXPR
string_type what() const
{
return reason_text;
@ -86,6 +89,7 @@ namespace etl
/// Gets the file for the exception.
/// \return const char* to the file.
//***************************************************************************
ETL_CONSTEXPR
string_type file_name() const
{
#if defined(ETL_VERBOSE_ERRORS)
@ -99,6 +103,7 @@ namespace etl
/// Gets the line for the exception.
/// \return const char* to the line.
//***************************************************************************
ETL_CONSTEXPR
numeric_type line_number() const
{
return line;

View File

@ -263,6 +263,7 @@ namespace etl
}
//********************************************
#include "etl/private/diagnostic_uninitialized_push.h"
void delete_current_message()
{
if (valid)
@ -272,6 +273,7 @@ namespace etl
pmsg->~imessage();
}
}
#include "etl/private/diagnostic_pop.h"
//********************************************
void add_new_message(const etl::imessage& msg)
@ -296,9 +298,6 @@ namespace etl
new (p) etl::remove_reference_t<TMessage>((etl::forward<TMessage>(msg)));
}
typename etl::aligned_storage<SIZE, ALIGNMENT>::type data;
bool valid;
//********************************************
template <typename TType>
bool add_new_message_type(const etl::imessage& msg)
@ -330,6 +329,9 @@ namespace etl
return false;
}
}
typename etl::aligned_storage<SIZE, ALIGNMENT>::type data;
bool valid;
};
#else
@ -628,6 +630,7 @@ namespace etl
cog.outl("private:")
cog.outl("")
cog.outl(" //********************************************")
cog.outl(" #include \"etl/private/diagnostic_uninitialized_push.h\"")
cog.outl(" void delete_current_message()")
cog.outl(" {")
cog.outl(" if (valid)")
@ -637,6 +640,7 @@ namespace etl
cog.outl(" pmsg->~imessage();")
cog.outl(" }")
cog.outl(" }")
cog.outl(" #include \"etl/private/diagnostic_pop.h\"")
cog.outl("")
cog.outl(" //********************************************")
cog.outl(" void add_new_message(const etl::imessage& msg)")
@ -910,6 +914,7 @@ namespace etl
cog.outl("private:")
cog.outl("")
cog.outl(" //********************************************")
cog.outl(" #include \"etl/private/diagnostic_uninitialized_push.h\"")
cog.outl(" void delete_current_message()")
cog.outl(" {")
cog.outl(" if (valid)")
@ -919,6 +924,7 @@ namespace etl
cog.outl(" pmsg->~imessage();")
cog.outl(" }")
cog.outl(" }")
cog.outl(" #include \"etl/private/diagnostic_pop.h\"")
cog.outl("")
cog.outl(" //********************************************")
cog.outl(" void add_new_message(const etl::imessage& msg)")

View File

@ -340,7 +340,7 @@ namespace etl
iterator& operator ++()
{
// Read the appropriate 'etl_next'.
p_value = static_cast<value_type*>(p_value->link_type::etl_next);
p_value = p_value->etl_next;
return *this;
}
@ -348,7 +348,7 @@ namespace etl
{
iterator temp(*this);
// Read the appropriate 'etl_next'.
p_value = static_cast<value_type*>(p_value->link_type::etl_next);
p_value = p_value->etl_next;
return temp;
}
@ -360,17 +360,17 @@ namespace etl
reference operator *() const
{
return *p_value;
return *static_cast<pointer>(p_value);
}
pointer operator &() const
{
return p_value;
return static_cast<pointer>(p_value);
}
pointer operator ->() const
{
return p_value;
return static_cast<pointer>(p_value);
}
friend bool operator == (const iterator& lhs, const iterator& rhs)
@ -385,12 +385,12 @@ namespace etl
private:
iterator(value_type* value)
iterator(link_type* value)
: p_value(value)
{
}
value_type* p_value;
link_type* p_value;
};
//*************************************************************************
@ -420,7 +420,7 @@ namespace etl
const_iterator& operator ++()
{
// Read the appropriate 'etl_next'.
p_value = static_cast<value_type*>(p_value->link_type::etl_next);
p_value = p_value->etl_next;
return *this;
}
@ -428,7 +428,7 @@ namespace etl
{
const_iterator temp(*this);
// Read the appropriate 'etl_next'.
p_value = static_cast<value_type*>(p_value->link_type::etl_next);
p_value = p_value->etl_next;
return temp;
}
@ -440,17 +440,17 @@ namespace etl
const_reference operator *() const
{
return *p_value;
return *static_cast<const value_type*>(p_value);
}
const_pointer operator &() const
{
return p_value;
return static_cast<const value_type*>(p_value);
}
const_pointer operator ->() const
{
return p_value;
return static_cast<const value_type*>(p_value);
}
friend bool operator == (const const_iterator& lhs, const const_iterator& rhs)
@ -465,12 +465,12 @@ namespace etl
private:
const_iterator(const value_type* value)
const_iterator(const link_type* value)
: p_value(value)
{
}
const value_type* p_value;
const link_type* p_value;
};
typedef typename etl::iterator_traits<iterator>::difference_type difference_type;
@ -505,7 +505,7 @@ namespace etl
//*************************************************************************
iterator begin()
{
return iterator(static_cast<value_type*>(this->get_head()));
return iterator(this->get_head());
}
//*************************************************************************
@ -513,7 +513,7 @@ namespace etl
//*************************************************************************
const_iterator begin() const
{
return const_iterator(static_cast<const value_type*>(this->get_head()));
return const_iterator(this->get_head());
}
//*************************************************************************
@ -521,7 +521,7 @@ namespace etl
//*************************************************************************
iterator before_begin()
{
return iterator(static_cast<value_type*>(&this->start_link));
return iterator(&this->start_link);
}
//*************************************************************************
@ -529,7 +529,7 @@ namespace etl
//*************************************************************************
const_iterator before_begin() const
{
return const_iterator(static_cast<const value_type*>(&this->start_link));
return const_iterator(&this->start_link);
}
//*************************************************************************
@ -537,7 +537,7 @@ namespace etl
//*************************************************************************
const_iterator cbegin() const
{
return const_iterator(static_cast<const value_type*>(this->get_head()));
return const_iterator(this->get_head());
}
//*************************************************************************
@ -569,7 +569,7 @@ namespace etl
//*************************************************************************
reference front()
{
return *static_cast<value_type*>(this->get_head());
return *static_cast<pointer>(this->get_head());
}
//*************************************************************************
@ -672,7 +672,7 @@ namespace etl
while (current != ETL_NULLPTR)
{
// Is this value the same as the last?
if (isEqual(*static_cast<value_type*>(current), *static_cast<value_type*>(last)))
if (isEqual(*static_cast<pointer>(current), *static_cast<pointer>(last)))
{
this->remove_link_after(*last);
}
@ -813,7 +813,7 @@ namespace etl
i_tail = i_link;
}
i_tail.p_value->link_type::etl_next = ETL_NULLPTR;
i_tail.p_value->etl_next = ETL_NULLPTR;
}
// Now left has stepped `list_size' places along, and right has too.
@ -894,14 +894,14 @@ namespace etl
}
link_type& before = *position.p_value;
link_type& after = *position.p_value->link_type::etl_next;
link_type& after = *position.p_value->etl_next;
etl::link<link_type>(before, first);
link_type* last = &before;
while (last->link_type::etl_next != ETL_NULLPTR)
while (last->etl_next != ETL_NULLPTR)
{
last = last->link_type::etl_next;
last = last->etl_next;
}
etl::link<link_type>(last, after);
@ -945,13 +945,13 @@ namespace etl
link_type* first = begin_.p_value;
link_type* last = first;
while (last->link_type::etl_next != end_.p_value)
while (last->etl_next != end_.p_value)
{
last = last->link_type::etl_next;
last = last->etl_next;
}
// Unlink from the source list.
link_type* first_next = first->link_type::etl_next;
link_type* first_next = first->etl_next;
etl::unlink_after(*first, *last);
// Fix our links.
@ -982,17 +982,17 @@ namespace etl
ETL_ASSERT(etl::is_sorted(begin(), end(), compare), ETL_ERROR(intrusive_forward_list_unsorted));
#endif
value_type* other_begin = static_cast<value_type*>(other.get_head());
value_type* other_terminal = ETL_NULLPTR;
link_type* other_begin = other.get_head();
link_type* other_terminal = ETL_NULLPTR;
value_type* before = static_cast<value_type*>(&this->start_link);
value_type* before_next = get_next(before);
value_type* terminal = ETL_NULLPTR;
link_type* before = &this->start_link;
link_type* before_next = get_next(before);
link_type* terminal = ETL_NULLPTR;
while ((before->link_type::etl_next != terminal) && (other_begin != other_terminal))
while ((before->etl_next != terminal) && (other_begin != other_terminal))
{
// Find the place to insert.
while ((before_next != terminal) && !(compare(*other_begin, *before_next)))
while ((before_next != terminal) && !(compare(*static_cast<pointer>(other_begin), *static_cast<pointer>(before_next))))
{
before = before_next;
before_next = get_next(before_next);
@ -1001,9 +1001,9 @@ namespace etl
// Insert.
if (before_next != terminal)
{
while ((other_begin != other_terminal) && (compare(*other_begin, *before_next)))
while ((other_begin != other_terminal) && (compare(*static_cast<pointer>(other_begin), *static_cast<pointer>(before_next))))
{
value_type* value = other_begin;
link_type* value = other_begin;
other_begin = get_next(other_begin);
etl::link_splice<link_type>(*before, *value);
before = get_next(before);
@ -1016,7 +1016,7 @@ namespace etl
{
while (other_begin != other_terminal)
{
value_type* value = other_begin;
link_type* value = other_begin;
other_begin = get_next(other_begin);
etl::link_splice<link_type>(*before, *value);
before = get_next(before);
@ -1034,9 +1034,9 @@ namespace etl
//*************************************************************************
/// Get the next value.
//*************************************************************************
value_type* get_next(link_type* link) const
link_type* get_next(link_type* link) const
{
return static_cast<value_type*>(link->etl_next);
return link->etl_next;
}
// Disabled.

View File

@ -395,7 +395,7 @@ namespace etl
iterator& operator ++()
{
// Read the appropriate 'etl_next'.
p_value = static_cast<value_type*>(p_value->link_type::etl_next);
p_value = p_value->etl_next;
return *this;
}
@ -403,14 +403,14 @@ namespace etl
{
iterator temp(*this);
// Read the appropriate 'etl_next'.
p_value = static_cast<value_type*>(p_value->link_type::etl_next);
p_value = p_value->etl_next;
return temp;
}
iterator& operator --()
{
// Read the appropriate 'etl_previous'.
p_value = static_cast<value_type*>(p_value->link_type::etl_previous);
p_value = p_value->etl_previous;
return *this;
}
@ -418,7 +418,7 @@ namespace etl
{
iterator temp(*this);
// Read the appropriate 'etl_previous'.
p_value = static_cast<value_type*>(p_value->link_type::etl_previous);
p_value = p_value->etl_previous;
return temp;
}
@ -430,17 +430,17 @@ namespace etl
reference operator *() const
{
return *p_value;
return *static_cast<pointer>(p_value);
}
pointer operator &() const
{
return p_value;
return static_cast<pointer>(p_value);
}
pointer operator ->() const
{
return p_value;
return *static_cast<pointer>(p_value);
}
friend bool operator == (const iterator& lhs, const iterator& rhs)
@ -455,12 +455,12 @@ namespace etl
private:
iterator(value_type* value)
iterator(link_type* value)
: p_value(value)
{
}
value_type* p_value;
link_type* p_value;
};
//*************************************************************************
@ -490,7 +490,7 @@ namespace etl
const_iterator& operator ++()
{
// Read the appropriate 'etl_next'.
p_value = static_cast<value_type*>(p_value->link_type::etl_next);
p_value = p_value->etl_next;
return *this;
}
@ -498,14 +498,14 @@ namespace etl
{
const_iterator temp(*this);
// Read the appropriate 'etl_next'.
p_value = static_cast<value_type*>(p_value->link_type::etl_next);
p_value = p_value->etl_next;
return temp;
}
const_iterator& operator --()
{
// Read the appropriate 'etl_previous'.
p_value = static_cast<value_type*>(p_value->link_type::etl_previous);
p_value = p_value->etl_previous;
return *this;
}
@ -513,7 +513,7 @@ namespace etl
{
const_iterator temp(*this);
// Read the appropriate 'etl_previous'.
p_value = static_cast<value_type*>(p_value->link_type::etl_previous);
p_value = p_value->etl_previous;
return temp;
}
@ -525,17 +525,17 @@ namespace etl
const_reference operator *() const
{
return *p_value;
return *static_cast<const_pointer>(p_value);
}
const_pointer operator &() const
{
return p_value;
return static_cast<const_pointer>(p_value);
}
const_pointer operator ->() const
{
return p_value;
return static_cast<const_pointer>(p_value);
}
friend bool operator == (const const_iterator& lhs, const const_iterator& rhs)
@ -550,12 +550,12 @@ namespace etl
private:
const_iterator(const value_type* value)
const_iterator(const link_type* value)
: p_value(value)
{
}
const value_type* p_value;
const link_type* p_value;
};
typedef typename etl::iterator_traits<iterator>::difference_type difference_type;
@ -590,7 +590,7 @@ namespace etl
//*************************************************************************
iterator begin()
{
return iterator(static_cast<value_type*>(this->get_head()));
return iterator(this->get_head());
}
//*************************************************************************
@ -598,7 +598,7 @@ namespace etl
//*************************************************************************
const_iterator begin() const
{
return const_iterator(static_cast<const value_type*>(this->get_head()));
return const_iterator(this->get_head());
}
//*************************************************************************
@ -606,7 +606,7 @@ namespace etl
//*************************************************************************
const_iterator cbegin() const
{
return const_iterator(static_cast<const value_type*>(this->get_head()));
return const_iterator(this->get_head());
}
//*************************************************************************
@ -614,7 +614,7 @@ namespace etl
//*************************************************************************
iterator end()
{
return iterator(static_cast<value_type*>(&this->terminal_link));
return iterator(&this->terminal_link);
}
//*************************************************************************
@ -622,7 +622,7 @@ namespace etl
//*************************************************************************
const_iterator end() const
{
return const_iterator(static_cast<const value_type*>(&this->terminal_link));
return const_iterator(&this->terminal_link);
}
//*************************************************************************
@ -630,7 +630,7 @@ namespace etl
//*************************************************************************
const_iterator cend() const
{
return const_iterator(static_cast<const value_type*>(&this->terminal_link));
return const_iterator(&this->terminal_link);
}
//*************************************************************************
@ -638,7 +638,7 @@ namespace etl
//*************************************************************************
reference front()
{
return *static_cast<value_type*>(this->get_head());
return *static_cast<pointer>(this->get_head());
}
//*************************************************************************
@ -646,7 +646,7 @@ namespace etl
//*************************************************************************
const_reference front() const
{
return *static_cast<const value_type*>(this->get_head());
return *static_cast<const_pointer>(this->get_head());
}
//*************************************************************************
@ -654,7 +654,7 @@ namespace etl
//*************************************************************************
reference back()
{
return *static_cast<value_type*>(this->get_tail());
return *static_cast<pointer>(this->get_tail());
}
//*************************************************************************
@ -662,7 +662,7 @@ namespace etl
//*************************************************************************
const_reference back() const
{
return *static_cast<const value_type*>(this->get_tail());
return *static_cast<const_pointer>(this->get_tail());
}
//*************************************************************************
@ -737,7 +737,7 @@ namespace etl
}
else
{
return iterator(static_cast<value_type*>(p_last));
return iterator(static_cast<pointer>(p_last));
}
}
@ -1047,28 +1047,28 @@ namespace etl
ETL_ASSERT(etl::is_sorted(begin(), end(), compare), ETL_ERROR(intrusive_list_unsorted));
#endif
value_type* other_begin = static_cast<value_type*>(other.get_head());
value_type* other_end = static_cast<value_type*>(&other.terminal_link);
link_type* other_begin = other.get_head();
link_type* other_end = &other.terminal_link;
value_type* this_begin = static_cast<value_type*>(this->get_head());
value_type* this_end = static_cast<value_type*>(&this->terminal_link);
link_type* this_begin = this->get_head();
link_type* this_end = &this->terminal_link;
while ((this_begin != this_end) && (other_begin != other_end))
{
// Find the place to insert.
while ((this_begin != this_end) && !(compare(*other_begin, *this_begin)))
while ((this_begin != this_end) && !(compare(*static_cast<pointer>(other_begin), *static_cast<pointer>(this_begin))))
{
this_begin = static_cast<value_type*>(this_begin->link_type::etl_next);
this_begin = this_begin->etl_next;
}
// Insert.
if (this_begin != this_end)
{
while ((other_begin != other_end) && (compare(*other_begin, *this_begin)))
while ((other_begin != other_end) && (compare(*static_cast<pointer>(other_begin), *static_cast<pointer>(this_begin))))
{
value_type* value = other_begin;
other_begin = static_cast<value_type*>(other_begin->link_type::etl_next);
etl::link_splice<link_type>(*this_begin->link_type::etl_previous, *value);
link_type* value = other_begin;
other_begin = other_begin->etl_next;
etl::link_splice<link_type>(*this_begin->etl_previous, *value);
}
}
}
@ -1076,7 +1076,7 @@ namespace etl
// Any left over?
if ((this_begin == this_end) && (other_begin != other_end))
{
etl::link_splice<link_type>(*this->get_tail(), *other_begin, *other_end->link_type::etl_previous);
etl::link_splice<link_type>(*this->get_tail(), *other_begin, *other_end->etl_previous);
}
this->current_size += other.size();

File diff suppressed because it is too large Load Diff

View File

@ -251,6 +251,7 @@ namespace etl
}
//********************************************
#include "etl/private/diagnostic_uninitialized_push.h"
void delete_current_message()
{
if (valid)
@ -260,6 +261,7 @@ namespace etl
pmsg->~imessage();
}
}
#include "etl/private/diagnostic_pop.h"
//********************************************
void add_new_message(const etl::imessage& msg)
@ -541,6 +543,7 @@ namespace etl
private:
//********************************************
#include "etl/private/diagnostic_uninitialized_push.h"
void delete_current_message()
{
if (valid)
@ -550,6 +553,7 @@ namespace etl
pmsg->~imessage();
}
}
#include "etl/private/diagnostic_pop.h"
//********************************************
void add_new_message(const etl::imessage& msg)
@ -832,6 +836,7 @@ namespace etl
private:
//********************************************
#include "etl/private/diagnostic_uninitialized_push.h"
void delete_current_message()
{
if (valid)
@ -841,6 +846,7 @@ namespace etl
pmsg->~imessage();
}
}
#include "etl/private/diagnostic_pop.h"
//********************************************
void add_new_message(const etl::imessage& msg)
@ -1121,6 +1127,7 @@ namespace etl
private:
//********************************************
#include "etl/private/diagnostic_uninitialized_push.h"
void delete_current_message()
{
if (valid)
@ -1130,6 +1137,7 @@ namespace etl
pmsg->~imessage();
}
}
#include "etl/private/diagnostic_pop.h"
//********************************************
void add_new_message(const etl::imessage& msg)
@ -1408,6 +1416,7 @@ namespace etl
private:
//********************************************
#include "etl/private/diagnostic_uninitialized_push.h"
void delete_current_message()
{
if (valid)
@ -1417,6 +1426,7 @@ namespace etl
pmsg->~imessage();
}
}
#include "etl/private/diagnostic_pop.h"
//********************************************
void add_new_message(const etl::imessage& msg)
@ -1689,6 +1699,7 @@ namespace etl
private:
//********************************************
#include "etl/private/diagnostic_uninitialized_push.h"
void delete_current_message()
{
if (valid)
@ -1698,6 +1709,7 @@ namespace etl
pmsg->~imessage();
}
}
#include "etl/private/diagnostic_pop.h"
//********************************************
void add_new_message(const etl::imessage& msg)
@ -1968,6 +1980,7 @@ namespace etl
private:
//********************************************
#include "etl/private/diagnostic_uninitialized_push.h"
void delete_current_message()
{
if (valid)
@ -1977,6 +1990,7 @@ namespace etl
pmsg->~imessage();
}
}
#include "etl/private/diagnostic_pop.h"
//********************************************
void add_new_message(const etl::imessage& msg)
@ -2245,6 +2259,7 @@ namespace etl
private:
//********************************************
#include "etl/private/diagnostic_uninitialized_push.h"
void delete_current_message()
{
if (valid)
@ -2254,6 +2269,7 @@ namespace etl
pmsg->~imessage();
}
}
#include "etl/private/diagnostic_pop.h"
//********************************************
void add_new_message(const etl::imessage& msg)
@ -2520,6 +2536,7 @@ namespace etl
private:
//********************************************
#include "etl/private/diagnostic_uninitialized_push.h"
void delete_current_message()
{
if (valid)
@ -2529,6 +2546,7 @@ namespace etl
pmsg->~imessage();
}
}
#include "etl/private/diagnostic_pop.h"
//********************************************
void add_new_message(const etl::imessage& msg)
@ -2789,6 +2807,7 @@ namespace etl
private:
//********************************************
#include "etl/private/diagnostic_uninitialized_push.h"
void delete_current_message()
{
if (valid)
@ -2798,6 +2817,7 @@ namespace etl
pmsg->~imessage();
}
}
#include "etl/private/diagnostic_pop.h"
//********************************************
void add_new_message(const etl::imessage& msg)
@ -3056,6 +3076,7 @@ namespace etl
private:
//********************************************
#include "etl/private/diagnostic_uninitialized_push.h"
void delete_current_message()
{
if (valid)
@ -3065,6 +3086,7 @@ namespace etl
pmsg->~imessage();
}
}
#include "etl/private/diagnostic_pop.h"
//********************************************
void add_new_message(const etl::imessage& msg)
@ -3321,6 +3343,7 @@ namespace etl
private:
//********************************************
#include "etl/private/diagnostic_uninitialized_push.h"
void delete_current_message()
{
if (valid)
@ -3330,6 +3353,7 @@ namespace etl
pmsg->~imessage();
}
}
#include "etl/private/diagnostic_pop.h"
//********************************************
void add_new_message(const etl::imessage& msg)
@ -3584,6 +3608,7 @@ namespace etl
private:
//********************************************
#include "etl/private/diagnostic_uninitialized_push.h"
void delete_current_message()
{
if (valid)
@ -3593,6 +3618,7 @@ namespace etl
pmsg->~imessage();
}
}
#include "etl/private/diagnostic_pop.h"
//********************************************
void add_new_message(const etl::imessage& msg)
@ -3841,6 +3867,7 @@ namespace etl
private:
//********************************************
#include "etl/private/diagnostic_uninitialized_push.h"
void delete_current_message()
{
if (valid)
@ -3850,6 +3877,7 @@ namespace etl
pmsg->~imessage();
}
}
#include "etl/private/diagnostic_pop.h"
//********************************************
void add_new_message(const etl::imessage& msg)
@ -4096,6 +4124,7 @@ namespace etl
private:
//********************************************
#include "etl/private/diagnostic_uninitialized_push.h"
void delete_current_message()
{
if (valid)
@ -4105,6 +4134,7 @@ namespace etl
pmsg->~imessage();
}
}
#include "etl/private/diagnostic_pop.h"
//********************************************
void add_new_message(const etl::imessage& msg)
@ -4349,6 +4379,7 @@ namespace etl
private:
//********************************************
#include "etl/private/diagnostic_uninitialized_push.h"
void delete_current_message()
{
if (valid)
@ -4358,6 +4389,7 @@ namespace etl
pmsg->~imessage();
}
}
#include "etl/private/diagnostic_pop.h"
//********************************************
void add_new_message(const etl::imessage& msg)
@ -4600,6 +4632,7 @@ namespace etl
private:
//********************************************
#include "etl/private/diagnostic_uninitialized_push.h"
void delete_current_message()
{
if (valid)
@ -4609,6 +4642,7 @@ namespace etl
pmsg->~imessage();
}
}
#include "etl/private/diagnostic_pop.h"
//********************************************
void add_new_message(const etl::imessage& msg)

View File

@ -33,6 +33,7 @@ SOFTWARE.
#include "platform.h"
#include "alignment.h"
#include "memory.h"
#include "type_traits.h"
#include "exception.h"
#include "error_handler.h"
@ -114,35 +115,34 @@ namespace etl
{
public:
#include "etl/private/diagnostic_uninitialized_push.h"
//***************************************************************************
/// Constructor.
//***************************************************************************
#include "etl/private/diagnostic_uninitialized_push.h"
ETL_CONSTEXPR
optional()
: valid(false)
: storage()
{
}
#include "etl/private/diagnostic_pop.h"
//***************************************************************************
/// Constructor with nullopt.
//***************************************************************************
#include "etl/private/diagnostic_uninitialized_push.h"
ETL_CONSTEXPR
optional(etl::nullopt_t)
: valid(false)
: storage()
{
}
#include "etl/private/diagnostic_pop.h"
//***************************************************************************
/// Copy constructor.
//***************************************************************************
ETL_CONSTEXPR20_STL
optional(const optional& other)
: valid(bool(other))
{
if (valid)
if (other.has_value())
{
::new (storage.template get_address<T>()) T(other.value());
storage.construct(other.value());
}
}
@ -150,12 +150,12 @@ namespace etl
//***************************************************************************
/// Move constructor.
//***************************************************************************
ETL_CONSTEXPR20_STL
optional(optional&& other)
: valid(bool(other))
{
if (valid)
if (other.has_value())
{
::new (storage.template get_address<T>()) T(etl::move(other.value()));
storage.construct(etl::move(other.value()));
}
}
#endif
@ -163,43 +163,42 @@ namespace etl
//***************************************************************************
/// Constructor from value type.
//***************************************************************************
ETL_CONSTEXPR20_STL
optional(const T& value_)
{
::new (storage.template get_address<T>()) T(value_);
valid = true;
storage.construct(value_);
}
#if ETL_USING_CPP11
//***************************************************************************
/// Constructor from value type.
//***************************************************************************
ETL_CONSTEXPR20_STL
optional(T&& value_)
{
::new (storage.template get_address<T>()) T(etl::move(value_));
valid = true;
storage.construct(etl::move(value_));
}
#endif
//***************************************************************************
/// Destructor.
//***************************************************************************
ETL_CONSTEXPR20_STL
~optional()
{
if (valid)
{
storage.template get_reference<T>().~T();
}
storage.destroy();
}
#include "etl/private/diagnostic_pop.h"
//***************************************************************************
/// Assignment operator from nullopt.
//***************************************************************************
ETL_CONSTEXPR20_STL
optional& operator =(etl::nullopt_t)
{
if (valid)
if (has_value())
{
storage.template get_reference<T>().~T();
valid = false;
storage.destroy();
}
return *this;
@ -208,26 +207,18 @@ namespace etl
//***************************************************************************
/// Assignment operator from optional.
//***************************************************************************
ETL_CONSTEXPR20_STL
optional& operator =(const optional& other)
{
if (this != &other)
{
if (valid && !bool(other))
if (other.has_value())
{
storage.template get_reference<T>().~T();
valid = false;
storage.construct(other.value());
}
else if (bool(other))
else
{
if (valid)
{
storage.template get_reference<T>() = other.value();
}
else
{
::new (storage.template get_address<T>()) T(other.value());
valid = true;
}
storage.destroy();
}
}
@ -238,26 +229,18 @@ namespace etl
//***************************************************************************
/// Assignment operator from optional.
//***************************************************************************
ETL_CONSTEXPR20_STL
optional& operator =(optional&& other)
{
if (this != &other)
{
if (valid && !bool(other))
if (other.has_value())
{
storage.template get_reference<T>().~T();
valid = false;
storage.construct(etl::move(other.value()));
}
else if (bool(other))
else
{
if (valid)
{
storage.template get_reference<T>() = etl::move(other.value());
}
else
{
::new (storage.template get_address<T>()) T(etl::move(other.value()));
valid = true;
}
storage.destroy();
}
}
@ -268,17 +251,10 @@ namespace etl
//***************************************************************************
/// Assignment operator from value type.
//***************************************************************************
ETL_CONSTEXPR20_STL
optional& operator =(const T& value_)
{
if (valid)
{
storage.template get_reference<T>() = value_;
}
else
{
::new (storage.template get_address<T>()) T(value_);
valid = true;
}
storage.construct(value_);
return *this;
}
@ -287,17 +263,10 @@ namespace etl
//***************************************************************************
/// Assignment operator from value type.
//***************************************************************************
ETL_CONSTEXPR20_STL
optional& operator =(T&& value_)
{
if (valid)
{
storage.template get_reference<T>() = etl::move(value_);
}
else
{
::new (storage.template get_address<T>()) T(etl::move(value_));
valid = true;
}
storage.construct(etl::move(value_));
return *this;
}
@ -306,102 +275,112 @@ namespace etl
//***************************************************************************
/// Pointer operator.
//***************************************************************************
ETL_CONSTEXPR20_STL
T* operator ->()
{
#if ETL_IS_DEBUG_BUILD
ETL_ASSERT(valid, ETL_ERROR(optional_invalid));
#if ETL_IS_DEBUG_BUILD && !(ETL_USING_CPP20 && ETL_USING_STL)
ETL_ASSERT(has_value(), ETL_ERROR(optional_invalid));
#endif
return storage.template get_address<T>();
return &storage.value;
}
//***************************************************************************
/// Pointer operator.
//***************************************************************************
ETL_CONSTEXPR20_STL
const T* operator ->() const
{
#if ETL_IS_DEBUG_BUILD
ETL_ASSERT(valid, ETL_ERROR(optional_invalid));
#if ETL_IS_DEBUG_BUILD && !(ETL_USING_CPP20 && ETL_USING_STL)
ETL_ASSERT(has_value(), ETL_ERROR(optional_invalid));
#endif
return storage.template get_address<T>();
return &storage.value;
}
//***************************************************************************
/// Dereference operator.
//***************************************************************************
ETL_CONSTEXPR20_STL
T& operator *()
{
#if ETL_IS_DEBUG_BUILD
ETL_ASSERT(valid, ETL_ERROR(optional_invalid));
#if ETL_IS_DEBUG_BUILD && !(ETL_USING_CPP20 && ETL_USING_STL)
ETL_ASSERT(has_value(), ETL_ERROR(optional_invalid));
#endif
return storage.template get_reference<T>();
return storage.value;
}
//***************************************************************************
/// Dereference operator.
//***************************************************************************
ETL_CONSTEXPR20_STL
const T& operator *() const
{
#if ETL_IS_DEBUG_BUILD
ETL_ASSERT(valid, ETL_ERROR(optional_invalid));
#if ETL_IS_DEBUG_BUILD && !(ETL_USING_CPP20 && ETL_USING_STL)
ETL_ASSERT(has_value(), ETL_ERROR(optional_invalid));
#endif
return storage.template get_reference<T>();
}
//***************************************************************************
/// Bool conversion operator.
//***************************************************************************
ETL_EXPLICIT operator bool() const
{
return valid;
return storage.value;
}
//***************************************************************************
// Check whether optional contains value
//***************************************************************************
ETL_CONSTEXPR bool has_value() const ETL_NOEXCEPT
ETL_CONSTEXPR20_STL
bool has_value() const ETL_NOEXCEPT
{
return valid;
return storage.valid;
}
//***************************************************************************
/// Bool conversion operator.
//***************************************************************************
ETL_CONSTEXPR20_STL
ETL_EXPLICIT operator bool() const
{
return has_value();
}
//***************************************************************************
/// Get a reference to the value.
//***************************************************************************
ETL_CONSTEXPR20_STL
T& value()
{
#if ETL_IS_DEBUG_BUILD
ETL_ASSERT(valid, ETL_ERROR(optional_invalid));
ETL_ASSERT(has_value(), ETL_ERROR(optional_invalid));
#endif
return storage.template get_reference<T>();
return storage.u.value;
}
//***************************************************************************
/// Get a const reference to the value.
//***************************************************************************
ETL_CONSTEXPR20_STL
const T& value() const
{
#if ETL_IS_DEBUG_BUILD
ETL_ASSERT(valid, ETL_ERROR(optional_invalid));
ETL_ASSERT(has_value(), ETL_ERROR(optional_invalid));
#endif
return storage.template get_reference<T>();
return storage.u.value;
}
//***************************************************************************
/// Gets the value or a default if no valid.
/// Gets the value or a default if not valid.
//***************************************************************************
ETL_CONSTEXPR20_STL
T value_or(T default_value) const
{
return valid ? value() : default_value;
return has_value() ? value() : default_value;
}
//***************************************************************************
/// Swaps this value with another.
//***************************************************************************
ETL_CONSTEXPR20_STL
void swap(optional& other)
{
optional temp(*this);
@ -412,13 +391,10 @@ namespace etl
//***************************************************************************
/// Reset back to invalid.
//***************************************************************************
ETL_CONSTEXPR20_STL
void reset()
{
if (valid)
{
storage.template get_reference<T>().~T();
valid = false;
}
storage.destroy();
}
#if ETL_USING_CPP11 && ETL_NOT_USING_STLPORT && !defined(ETL_OPTIONAL_FORCE_CPP03_IMPLEMENTATION)
@ -426,17 +402,11 @@ namespace etl
/// Emplaces a value.
///\param args The arguments to construct with.
//*************************************************************************
template <typename ... Args>
void emplace(Args && ... args)
ETL_CONSTEXPR20_STL
template <typename ... TArgs>
void emplace(TArgs&& ... args)
{
if (valid)
{
// Destroy the old one.
storage.template get_reference<T>().~T();
}
::new (storage.template get_address<T>()) T(ETL_OR_STD::forward<Args>(args)...);
valid = true;
storage.construct(etl::forward<TArgs>(args)...);
}
#else
//*************************************************************************
@ -446,14 +416,13 @@ namespace etl
template <typename T1>
void emplace(const T1& value1)
{
if (valid)
if (has_value())
{
// Destroy the old one.
storage.template get_reference<T>().~T();
storage.destroy();
}
::new (storage.template get_address<T>()) T(value1);
valid = true;
::new (&storage.value) T(value1);
}
//*************************************************************************
@ -463,14 +432,13 @@ namespace etl
template <typename T1, typename T2>
void emplace(const T1& value1, const T2& value2)
{
if (valid)
if (has_value())
{
// Destroy the old one.
storage.template get_reference<T>().~T();
storage.destroy();
}
::new (storage.template get_address<T>()) T(value1, value2);
valid = true;
::new (&storage.value) T(value1, value2);
}
//*************************************************************************
@ -480,14 +448,13 @@ namespace etl
template <typename T1, typename T2, typename T3>
void emplace(const T1& value1, const T2& value2, const T3& value3)
{
if (valid)
if (has_value())
{
// Destroy the old one.
storage.template get_reference<T>().~T();
storage.destroy();
}
::new (storage.template get_address<T>()) T(value1, value2, value3);
valid = true;
::new (&storage.value) T(value1, value2, value3);
}
//*************************************************************************
@ -497,21 +464,111 @@ namespace etl
template <typename T1, typename T2, typename T3, typename T4>
void emplace(const T1& value1, const T2& value2, const T3& value3, const T4& value4)
{
if (valid)
if (has_value())
{
// Destroy the old one.
storage.template get_reference<T>().~T();
storage.destroy();
}
::new (storage.template get_address<T>()) T(value1, value2, value3, value4);
valid = true;
::new (&storage.value) T(value1, value2, value3, value4);
}
#endif
private:
bool valid;
typename etl::aligned_storage_as<sizeof(T), T>::type storage;
struct storage_type
{
//*******************************
ETL_CONSTEXPR20_STL
storage_type()
: u()
, valid(false)
{
u.dummy = 0;
}
//*******************************
ETL_CONSTEXPR20_STL
~storage_type()
{
destroy();
}
//*******************************
ETL_CONSTEXPR20_STL
void construct(const T& value_)
{
if (valid)
{
u.value = value_;
}
else
{
etl::construct_at(&u.value, value_);
valid = true;
}
}
#if ETL_USING_CPP11
//*******************************
ETL_CONSTEXPR20_STL
void construct(T&& value_)
{
if (valid)
{
u.value = etl::move(value_);
}
else
{
etl::construct_at(&u.value, etl::move(value_));
valid = true;
}
}
//*******************************
template <typename... TArgs>
ETL_CONSTEXPR20_STL
void construct(TArgs... args)
{
destroy();
etl::construct_at(&u.value, etl::forward<TArgs>(args)...);
valid = true;
}
#endif
//*******************************
ETL_CONSTEXPR20_STL
void destroy()
{
if (valid)
{
etl::destroy_at(&u.value);
valid = false;
}
}
//*******************************
union union_type
{
ETL_CONSTEXPR20_STL
union_type()
: dummy(0)
{
}
ETL_CONSTEXPR20_STL
~union_type()
{
}
char dummy;
T value;
} u;
bool valid;
};
storage_type storage;
};
//*****************************************************************************

View File

@ -318,6 +318,12 @@ SOFTWARE.
#define ETL_NO_UNIQUE_ADDRESS
#endif
#if ETL_USING_CPP20 && ETL_USING_STL
#define ETL_CONSTEXPR20_STL constexpr
#else
#define ETL_CONSTEXPR20_STL
#endif
//*************************************
// Determine if the ETL can use char8_t type.
#if ETL_USING_8BIT_TYPES

View File

@ -476,6 +476,7 @@ namespace etl
/// Copy constructor.
///\param other The other variant object to copy.
//***************************************************************************
#include "etl/private/diagnostic_uninitialized_push.h"
variant(const variant& other)
{
switch (other.type_id)
@ -493,6 +494,7 @@ namespace etl
type_id = other.type_id;
}
#include "etl/private/diagnostic_pop.h"
#if ETL_USING_CPP11 && ETL_NOT_USING_STLPORT && !defined(ETL_VARIANT_FORCE_CPP03_IMPLEMENTATION)
//*************************************************************************
@ -845,6 +847,7 @@ namespace etl
private:
#include "etl/private/diagnostic_uninitialized_push.h"
//***************************************************************************
/// Destruct the current occupant of the variant.
//***************************************************************************
@ -865,6 +868,7 @@ namespace etl
type_id = UNSUPPORTED_TYPE_ID;
}
#include "etl/private/diagnostic_pop.h"
//***************************************************************************
/// The internal storage.

View File

@ -168,6 +168,12 @@ SOFTWARE.
#define ETL_USING_CPP20 (ETL_CPP20_SUPPORTED == 1)
#define ETL_USING_CPP23 (ETL_CPP23_SUPPORTED == 1)
#define ETL_NOT_USING_CPP11 (ETL_CPP11_SUPPORTED == 0)
#define ETL_NOT_USING_CPP14 (ETL_CPP14_SUPPORTED == 0)
#define ETL_NOT_USING_CPP17 (ETL_CPP17_SUPPORTED == 0)
#define ETL_NOT_USING_CPP20 (ETL_CPP20_SUPPORTED == 0)
#define ETL_NOT_USING_CPP23 (ETL_CPP23_SUPPORTED == 0)
// Language standard
#if ETL_USING_CPP23
#define ETL_LANGUAGE_STANDARD 23

View File

@ -294,6 +294,21 @@ if (ETL_FORCE_TEST_CPP03_IMPLEMENTATION)
target_compile_definitions(etl_tests PRIVATE -DETL_FORCE_TEST_CPP03_IMPLEMENTATION)
endif()
if (ETL_OPTIMISATION MATCHES "-O1")
message(STATUS "Compiling with -O1 optimisations")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O1")
endif()
if (ETL_OPTIMISATION MATCHES "-O2")
message(STATUS "Compiling with -O2 optimisations")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2")
endif()
if (ETL_OPTIMISATION MATCHES "-O3")
message(STATUS "Compiling with -O3 optimisations")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
endif()
target_include_directories(etl_tests
PRIVATE
${PROJECT_SOURCE_DIR}/../include)
@ -304,14 +319,16 @@ target_link_libraries(etl_tests PRIVATE UnitTestpp)
if ((CMAKE_CXX_COMPILER_ID MATCHES "GNU") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
target_compile_options(etl_tests
PRIVATE
-fsanitize=address,undefined
-pipe
-fsanitize=address,undefined,bounds
-fno-omit-frame-pointer
-Wall
-Wextra
-Werror
)
target_link_options(etl_tests
PRIVATE
-fsanitize=address,undefined
-fsanitize=address,undefined,bounds
)
endif ()

View File

@ -14,11 +14,42 @@ add_executable(etl_tests
${TEST_SOURCE_FILES}
)
if (ETL_OPTIMISATION MATCHES "-O1")
message(STATUS "Compiling with -O1 optimisations")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O1")
endif()
if (ETL_OPTIMISATION MATCHES "-O2")
message(STATUS "Compiling with -O2 optimisations")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2")
endif()
if (ETL_OPTIMISATION MATCHES "-O3")
message(STATUS "Compiling with -O3 optimisations")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
endif()
target_include_directories(etl_tests
PUBLIC
${CMAKE_CURRENT_LIST_DIR}
)
if ((CMAKE_CXX_COMPILER_ID MATCHES "GNU") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
target_compile_options(etl_tests
PRIVATE
-pipe
-fsanitize=address,undefined,bounds
-fno-omit-frame-pointer
-Wall
-Wextra
-Werror
)
target_link_options(etl_tests
PRIVATE
-fsanitize=address,undefined,bounds
)
endif ()
# Enable the 'make test' CMake target using the executable defined above
add_test(etl_error_handler_unit_tests etl_tests)

View File

@ -14,11 +14,42 @@ add_executable(etl_tests
${TEST_SOURCE_FILES}
)
if (ETL_OPTIMISATION MATCHES "-O1")
message(STATUS "Compiling with -O1 optimisations")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O1")
endif()
if (ETL_OPTIMISATION MATCHES "-O2")
message(STATUS "Compiling with -O2 optimisations")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2")
endif()
if (ETL_OPTIMISATION MATCHES "-O3")
message(STATUS "Compiling with -O3 optimisations")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
endif()
target_include_directories(etl_tests
PUBLIC
${CMAKE_CURRENT_LIST_DIR}
)
if ((CMAKE_CXX_COMPILER_ID MATCHES "GNU") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
target_compile_options(etl_tests
PRIVATE
-pipe
-fsanitize=address,undefined,bounds
-fno-omit-frame-pointer
-Wall
-Wextra
-Werror
)
target_link_options(etl_tests
PRIVATE
-fsanitize=address,undefined,bounds
)
endif ()
# Enable the 'make test' CMake target using the executable defined above
add_test(etl_error_handler_unit_tests etl_tests)

View File

@ -41,7 +41,7 @@ struct ErrorLog
{
}
void Log(const etl::exception& e)
void Log(const etl::exception& /*e*/)
{
++log_count;
}

View File

@ -15,11 +15,42 @@ add_executable(etl_tests
${TEST_SOURCE_FILES}
)
if (ETL_OPTIMISATION MATCHES "-O1")
message(STATUS "Compiling with -O1 optimisations")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O1")
endif()
if (ETL_OPTIMISATION MATCHES "-O2")
message(STATUS "Compiling with -O2 optimisations")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2")
endif()
if (ETL_OPTIMISATION MATCHES "-O3")
message(STATUS "Compiling with -O3 optimisations")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
endif()
target_include_directories(etl_tests
PUBLIC
${CMAKE_CURRENT_LIST_DIR}
)
if ((CMAKE_CXX_COMPILER_ID MATCHES "GNU") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
target_compile_options(etl_tests
PRIVATE
-pipe
-fsanitize=address,undefined,bounds
-fno-omit-frame-pointer
-Wall
-Wextra
-Werror
)
target_link_options(etl_tests
PRIVATE
-fsanitize=address,undefined,bounds
)
endif ()
# Enable the 'make test' CMake target using the executable defined above
add_test(etl_error_handler_unit_tests etl_tests)

View File

@ -41,7 +41,7 @@ struct ErrorLog
{
}
void Log(const etl::exception& e)
void Log(const etl::exception& /*e*/)
{
++log_count;
}

View File

@ -15,11 +15,42 @@ add_executable(etl_tests
${TEST_SOURCE_FILES}
)
if (ETL_OPTIMISATION MATCHES "-O1")
message(STATUS "Compiling with -O1 optimisations")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O1")
endif()
if (ETL_OPTIMISATION MATCHES "-O2")
message(STATUS "Compiling with -O2 optimisations")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2")
endif()
if (ETL_OPTIMISATION MATCHES "-O3")
message(STATUS "Compiling with -O3 optimisations")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
endif()
target_include_directories(etl_tests
PUBLIC
${CMAKE_CURRENT_LIST_DIR}
)
if ((CMAKE_CXX_COMPILER_ID MATCHES "GNU") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
target_compile_options(etl_tests
PRIVATE
-pipe
-fsanitize=address,undefined,bounds
-fno-omit-frame-pointer
-Wall
-Wextra
-Werror
)
target_link_options(etl_tests
PRIVATE
-fsanitize=address,undefined,bounds
)
endif ()
# Enable the 'make test' CMake target using the executable defined above
add_test(etl_initializer_list_unit_tests etl_tests)

View File

@ -37,8 +37,8 @@ public:
//#if ETL_USING_INITIALIZER_LIST
constexpr Container(std::initializer_list<T> init)
: buffer()
, length(init.size())
: length(init.size())
, buffer()
{
typename std::initializer_list<T>::const_iterator itr = std::begin(init);
T* p = buffer;

238
test/runtests-02.sh Normal file
View File

@ -0,0 +1,238 @@
#!/bin/sh
clear
mkdir -p build-make || exit 1
cd build-make || exit 1
echo "ETL Tests" > log.txt
opt="-O2"
#******************************************************************************
# GCC
#******************************************************************************
echo ""
echo "-----------------------------------------------" | tee -a log.txt
echo " GCC - STL" | tee -a log.txt
echo "-----------------------------------------------" | tee -a log.txt
rm * -rf
gcc --version | grep gcc | tee -a log.txt
cmake -DCMAKE_CXX_COMPILER="g++" -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF -DETL_OPTIMISATION=$opt ..
make -j4
if [ $? -eq 0 ]; then
echo "<<<< Passed Compilation >>>>"
else
echo "****************\n**** Failed ****\n****************" | tee -a ../log.txt
exit $?
fi
./etl_tests
if [ $? -eq 0 ]; then
echo "<<<< Passed Tests >>>>"
else
echo "****************\n**** Failed ****\n****************" | tee -a ../log.txt
exit $?
fi
echo ""
echo "-----------------------------------------------" | tee -a log.txt
echo " GCC - Initializer list test" | tee -a log.txt
echo "-----------------------------------------------" | tee -a log.txt
cd ../etl_initializer_list/
mkdir -p build-make || exit 1
cd build-make || exit 1
rm * -rf
gcc --version | grep gcc | tee -a log.txt
cmake -DCMAKE_CXX_COMPILER="g++" -DETL_OPTIMISATION=$opt ..
make -j4
if [ $? -eq 0 ]; then
echo "<<<< Passed initializer_list Compilation >>>>"
else
echo "****************\n**** Failed initializer_list ****\n****************" | tee -a ../log.txt
exit $?
fi
./etl_tests
if [ $? -eq 0 ]; then
echo "<<<< Passed Tests >>>>"
else
echo "****************\n**** Failed ****\n****************" | tee -a ../log.txt
exit $?
fi
echo ""
echo "-----------------------------------------------" | tee -a log.txt
echo " Clang - Initializer list test" | tee -a log.txt
echo "-----------------------------------------------" | tee -a log.txt
rm * -rf
clang --version | grep clang | tee -a log.txt
cmake -DCMAKE_CXX_COMPILER="clang++" -DETL_OPTIMISATION=$opt ..
make -j4
if [ $? -eq 0 ]; then
echo "<<<< Passed initializer_list Compilation >>>>"
else
echo "****************\n**** Failed initializer_list ****\n****************" | tee -a ../log.txt
exit $?
fi
./etl_tests
if [ $? -eq 0 ]; then
echo "<<<< Passed Tests >>>>"
else
echo "****************\n**** Failed ****\n****************" | tee -a ../log.txt
exit $?
fi
echo ""
echo "-----------------------------------------------" | tee -a log.txt
echo " GCC - Error macros 'log_errors' test" | tee -a log.txt
echo "-----------------------------------------------" | tee -a log.txt
cd ../../etl_error_handler/log_errors
mkdir -p build-make || exit 1
cd build-make || exit 1
rm * -rf
gcc --version | grep gcc | tee -a log.txt
cmake -DCMAKE_CXX_COMPILER="g++" -DETL_OPTIMISATION=$opt ..
make -j4
if [ $? -eq 0 ]; then
echo "<<<< Passed Error macros 'log_errors' Compilation >>>>"
else
echo "****************\n**** Failed Error macros 'log_errors' ****\n****************" | tee -a ../log.txt
exit $?
fi
./etl_tests
if [ $? -eq 0 ]; then
echo "<<<< Passed Tests >>>>"
else
echo "****************\n**** Failed Error macros 'log_errors' ****\n****************" | tee -a ../log.txt
exit $?
fi
echo ""
echo "-----------------------------------------------" | tee -a log.txt
echo " GCC - Error macros 'exceptions' test" | tee -a log.txt
echo "-----------------------------------------------" | tee -a log.txt
cd ../../../etl_error_handler/exceptions
mkdir -p build-make || exit 1
cd build-make || exit 1
rm * -rf
gcc --version | grep gcc | tee -a log.txt
cmake -DCMAKE_CXX_COMPILER="g++" -DETL_OPTIMISATION=$opt ..
make -j4
if [ $? -eq 0 ]; then
echo "<<<< Passed Error macros 'exceptions' Compilation >>>>"
else
echo "****************\n**** Failed Error macros 'exceptions' ****\n****************" | tee -a ../log.txt
exit $?
fi
./etl_tests
if [ $? -eq 0 ]; then
echo "<<<< Passed Tests >>>>"
else
echo "****************\n**** Failed Error macros 'exceptions' ****\n****************" | tee -a ../log.txt
exit $?
fi
echo ""
echo "-----------------------------------------------" | tee -a log.txt
echo " GCC - Error macros 'log_errors and exceptions' test" | tee -a log.txt
echo "-----------------------------------------------" | tee -a log.txt
cd ../../../etl_error_handler/log_errors_and_exceptions
mkdir -p build-make || exit 1
cd build-make || exit 1
rm * -rf
gcc --version | grep gcc | tee -a log.txt
cmake -DCMAKE_CXX_COMPILER="g++" -DETL_OPTIMISATION=$opt ..
make -j4
if [ $? -eq 0 ]; then
echo "<<<< Passed Error macros 'log_errors and exceptions' Compilation >>>>"
else
echo "****************\n**** Failed Error macros 'log_errors and exceptions' ****\n****************" | tee -a ../log.txt
exit $?
fi
./etl_tests
if [ $? -eq 0 ]; then
echo "<<<< Passed Tests >>>>"
else
echo "****************\n**** Failed Error macros 'log_errors and exceptions' ****\n****************" | tee -a ../log.txt
exit $?
fi
echo ""
echo "-----------------------------------------------" | tee -a log.txt
echo " Clang - Error macros 'log_errors' test" | tee -a log.txt
echo "-----------------------------------------------" | tee -a log.txt
cd ../../../etl_error_handler/log_errors
mkdir -p build-make || exit 1
cd build-make || exit 1
rm * -rf
clang --version | grep clang | tee -a log.txt
cmake -DCMAKE_CXX_COMPILER="clang++" -DETL_OPTIMISATION=$opt ..
make -j4
if [ $? -eq 0 ]; then
echo "<<<< Passed Error macros 'log_errors' Compilation >>>>"
else
echo "****************\n**** Failed Error macros 'log_errors' ****\n****************" | tee -a ../log.txt
exit $?
fi
./etl_tests
if [ $? -eq 0 ]; then
echo "<<<< Passed Tests >>>>"
else
echo "****************\n**** Failed Error macros 'log_errors' ****\n****************" | tee -a ../log.txt
exit $?
fi
echo ""
echo "-----------------------------------------------" | tee -a log.txt
echo " Clang - Error macros 'exceptions' test" | tee -a log.txt
echo "-----------------------------------------------" | tee -a log.txt
cd ../../../etl_error_handler/exceptions
mkdir -p build-make || exit 1
cd build-make || exit 1
rm * -rf
clang --version | grep clang | tee -a log.txt
cmake -DCMAKE_CXX_COMPILER="clang++" -DETL_OPTIMISATION=$opt ..
make -j4
if [ $? -eq 0 ]; then
echo "<<<< Passed Error macros 'exceptions' Compilation >>>>"
else
echo "****************\n**** Failed Error macros 'exceptions' ****\n****************" | tee -a ../log.txt
exit $?
fi
./etl_tests
if [ $? -eq 0 ]; then
echo "<<<< Passed Tests >>>>"
else
echo "****************\n**** Failed Error macros 'exceptions' ****\n****************" | tee -a ../log.txt
exit $?
fi
echo ""
echo "-----------------------------------------------" | tee -a log.txt
echo " Clang - Error macros 'log_errors and exceptions' test" | tee -a log.txt
echo "-----------------------------------------------" | tee -a log.txt
cd ../../../etl_error_handler/log_errors_and_exceptions
mkdir -p build-make || exit 1
cd build-make || exit 1
rm * -rf
clang --version | grep clang | tee -a log.txt
cmake -DCMAKE_CXX_COMPILER="clang++" -DETL_OPTIMISATION=$opt ..
make -j4
if [ $? -eq 0 ]; then
echo "<<<< Passed Error macros 'log_errors and exceptions' Compilation >>>>"
else
echo "****************\n**** Failed Error macros 'log_errors and exceptions' ****\n****************" | tee -a ../log.txt
exit $?
fi
./etl_tests
if [ $? -eq 0 ]; then
echo "<<<< Passed Tests >>>>"
else
echo "****************\n**** Failed Error macros 'log_errors and exceptions' ****\n****************" | tee -a ../log.txt
exit $?
fi
cd ../..
echo ""
echo "-----------------------------------------------" | tee -a log.txt
echo " All Tests Completed OK" | tee -a log.txt
echo "-----------------------------------------------" | tee -a log.txt

View File

@ -6,6 +6,8 @@ cd build-make || exit 1
echo "ETL Tests" > log.txt
opt="-O0"
#******************************************************************************
# GCC
#******************************************************************************
@ -15,7 +17,7 @@ echo " GCC - STL" | tee -a log.txt
echo "-----------------------------------------------" | tee -a log.txt
rm * -rf
gcc --version | grep gcc | tee -a log.txt
cmake -DCMAKE_CXX_COMPILER="g++" -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF ..
cmake -DCMAKE_CXX_COMPILER="g++" -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF -DETL_OPTIMISATION=$opt ..
make -j4
if [ $? -eq 0 ]; then
echo "<<<< Passed Compilation >>>>"
@ -36,7 +38,7 @@ echo " GCC - STL - Force C++03" | tee -a log.txt
echo "-----------------------------------------------" | tee -a log.txt
rm * -rf
gcc --version | grep gcc | tee -a log.txt
cmake -DCMAKE_CXX_COMPILER="g++" -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON ..
cmake -DCMAKE_CXX_COMPILER="g++" -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON -DETL_OPTIMISATION=$opt ..
make -j4
if [ $? -eq 0 ]; then
echo "<<<< Passed Compilation >>>>"
@ -57,7 +59,7 @@ echo " GCC - No STL" | tee -a log.txt
echo "-----------------------------------------------" | tee -a log.txt
rm * -rf
gcc --version | grep gcc | tee -a log.txt
cmake -DCMAKE_CXX_COMPILER="g++" -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF ..
cmake -DCMAKE_CXX_COMPILER="g++" -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF -DETL_OPTIMISATION=$opt ..
make -j4
if [ $? -eq 0 ]; then
echo "<<<< Passed Compilation >>>>"
@ -82,7 +84,7 @@ echo " Clang - STL" | tee -a log.txt
echo "-----------------------------------------------" | tee -a log.txt
rm * -rf
clang --version | grep clang | tee -a log.txt
cmake -DCMAKE_CXX_COMPILER="clang++" -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF ..
cmake -DCMAKE_CXX_COMPILER="clang++" -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF -DETL_OPTIMISATION=$opt ..
make -j4
if [ $? -eq 0 ]; then
echo "<<<< Passed Compilation >>>>"
@ -103,7 +105,7 @@ echo " Clang - STL - Force C++03" | tee -a log.txt
echo "-----------------------------------------------" | tee -a log.txt
rm * -rf
clang --version | grep clang | tee -a log.txt
cmake -DCMAKE_CXX_COMPILER="clang++" -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON ..
cmake -DCMAKE_CXX_COMPILER="clang++" -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON -DETL_OPTIMISATION=$opt ..
make -j4
if [ $? -eq 0 ]; then
echo "<<<< Passed Compilation >>>>"
@ -124,7 +126,7 @@ echo " Clang - No STL" | tee -a log.txt
echo "-----------------------------------------------" | tee -a log.txt
rm * -rf
clang --version | grep clang | tee -a log.txt
cmake -DCMAKE_CXX_COMPILER="clang++" -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF ..
cmake -DCMAKE_CXX_COMPILER="clang++" -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF -DETL_OPTIMISATION=$opt ..
make -j4
if [ $? -eq 0 ]; then
echo "<<<< Passed Compilation >>>>"
@ -149,7 +151,7 @@ mkdir -p build-make || exit 1
cd build-make || exit 1
rm * -rf
gcc --version | grep gcc | tee -a log.txt
cmake -DCMAKE_CXX_COMPILER="g++" ..
cmake -DCMAKE_CXX_COMPILER="g++" -DETL_OPTIMISATION=$opt ..
make -j4
if [ $? -eq 0 ]; then
echo "<<<< Passed initializer_list Compilation >>>>"
@ -171,7 +173,7 @@ echo " Clang - Initializer list test" | tee -a log.txt
echo "-----------------------------------------------" | tee -a log.txt
rm * -rf
clang --version | grep clang | tee -a log.txt
cmake -DCMAKE_CXX_COMPILER="clang++" ..
cmake -DCMAKE_CXX_COMPILER="clang++" -DETL_OPTIMISATION=$opt ..
make -j4
if [ $? -eq 0 ]; then
echo "<<<< Passed initializer_list Compilation >>>>"
@ -196,7 +198,7 @@ mkdir -p build-make || exit 1
cd build-make || exit 1
rm * -rf
gcc --version | grep gcc | tee -a log.txt
cmake -DCMAKE_CXX_COMPILER="g++" ..
cmake -DCMAKE_CXX_COMPILER="g++" -DETL_OPTIMISATION=$opt ..
make -j4
if [ $? -eq 0 ]; then
echo "<<<< Passed Error macros 'log_errors' Compilation >>>>"
@ -221,7 +223,7 @@ mkdir -p build-make || exit 1
cd build-make || exit 1
rm * -rf
gcc --version | grep gcc | tee -a log.txt
cmake -DCMAKE_CXX_COMPILER="g++" ..
cmake -DCMAKE_CXX_COMPILER="g++" -DETL_OPTIMISATION=$opt ..
make -j4
if [ $? -eq 0 ]; then
echo "<<<< Passed Error macros 'exceptions' Compilation >>>>"
@ -246,7 +248,7 @@ mkdir -p build-make || exit 1
cd build-make || exit 1
rm * -rf
gcc --version | grep gcc | tee -a log.txt
cmake -DCMAKE_CXX_COMPILER="g++" ..
cmake -DCMAKE_CXX_COMPILER="g++" -DETL_OPTIMISATION=$opt ..
make -j4
if [ $? -eq 0 ]; then
echo "<<<< Passed Error macros 'log_errors and exceptions' Compilation >>>>"
@ -271,7 +273,7 @@ mkdir -p build-make || exit 1
cd build-make || exit 1
rm * -rf
clang --version | grep clang | tee -a log.txt
cmake -DCMAKE_CXX_COMPILER="clang++" ..
cmake -DCMAKE_CXX_COMPILER="clang++" -DETL_OPTIMISATION=$opt ..
make -j4
if [ $? -eq 0 ]; then
echo "<<<< Passed Error macros 'log_errors' Compilation >>>>"
@ -296,7 +298,7 @@ mkdir -p build-make || exit 1
cd build-make || exit 1
rm * -rf
clang --version | grep clang | tee -a log.txt
cmake -DCMAKE_CXX_COMPILER="clang++" ..
cmake -DCMAKE_CXX_COMPILER="clang++" -DETL_OPTIMISATION=$opt ..
make -j4
if [ $? -eq 0 ]; then
echo "<<<< Passed Error macros 'exceptions' Compilation >>>>"
@ -321,7 +323,7 @@ mkdir -p build-make || exit 1
cd build-make || exit 1
rm * -rf
clang --version | grep clang | tee -a log.txt
cmake -DCMAKE_CXX_COMPILER="clang++" ..
cmake -DCMAKE_CXX_COMPILER="clang++" -DETL_OPTIMISATION=$opt ..
make -j4
if [ $? -eq 0 ]; then
echo "<<<< Passed Error macros 'log_errors and exceptions' Compilation >>>>"

View File

@ -33,7 +33,6 @@ SOFTWARE.
#include <optional>
#include "etl/optional.h"
#include "etl/vector.h"
#include "data.h"
@ -57,442 +56,451 @@ namespace
{
SUITE(test_optional)
{
//*************************************************************************
TEST(test_initialisation)
{
etl::optional<Data> data1;
etl::optional<Data> data2;
CHECK(!bool(data1));
CHECK(!bool(data2));
CHECK(!data1.has_value());
CHECK(!data2.has_value());
data1 = Data("Hello");
CHECK(bool(data1));
CHECK(data1.has_value());
CHECK_EQUAL(Data("Hello"), data1);
data1 = data2;
CHECK(!bool(data1));
CHECK(!bool(data2));
CHECK(!data1.has_value());
CHECK(!data2.has_value());
data1 = Data("World");
data2 = data1;
CHECK(bool(data1));
CHECK(bool(data2));
CHECK(data1.has_value());
CHECK(data2.has_value());
etl::optional<Data> data3(data1);
CHECK(bool(data3));
CHECK(data3.has_value());
CHECK_EQUAL(data1, data3);
etl::optional<Data> data4;
data4 = Data("Hello");
data4 = etl::nullopt;
CHECK(!bool(data4));
CHECK(!data4.has_value());
}
//*************************************************************************
TEST(test_deduced_initialisation)
{
Data data("Hello");
etl::optional opt{ data };
CHECK(opt.has_value());
CHECK(bool(opt));
CHECK_EQUAL(data, opt);
}
//*************************************************************************
TEST(test_emplace)
{
etl::optional<DataM> data;
data.emplace(1U);
CHECK_EQUAL(1U, data.value().value);
data.emplace(2U);
CHECK_EQUAL(2U, data.value().value);
data.emplace(3U);
CHECK_EQUAL(3U, data.value().value);
CHECK_EQUAL(1, DataM::get_instance_count());
}
//*************************************************************************
TEST(test_moveable)
{
#include "etl/private/diagnostic_pessimizing_move_push.h"
etl::optional<DataM> data(std::move(DataM(1)));
CHECK_EQUAL(1U, data.value().value);
CHECK(bool(data));
data = std::move(etl::optional<DataM>(std::move(DataM(2))));
CHECK_EQUAL(2U, data.value().value);
CHECK(bool(data));
etl::optional<DataM> data2(etl::move(data));
CHECK_EQUAL(2U, data2.value().value);
CHECK(bool(data2));
#include "etl/private/diagnostic_pop.h"
}
//*************************************************************************
TEST(test_nullopt)
{
etl::optional<Data> data;
data = Data("Hello");
data = etl::nullopt;
CHECK(!bool(data));
}
//*************************************************************************
TEST(test_value_or)
{
etl::optional<Data> data;
Data result = data.value_or(Data("Default"));
CHECK_EQUAL(Data("Default"), result);
data = Data("Value");
result = data.value_or(Data("Default"));
CHECK_EQUAL(Data("Value"), result);
}
//*************************************************************************
TEST(test_equality)
{
etl::optional<Data> data1;
etl::optional<Data> data2;
CHECK(data1 == data2);
CHECK(data2 == data1);
data1 = Data("Data1");
CHECK(!(data1 == data2));
CHECK(!(data2 == data1));
data1 = etl::nullopt;
data2 = Data("Data2");
CHECK(!(data1 == data2));
CHECK(!(data2 == data1));
data1 = Data("Data1");
data2 = Data("Data1");
CHECK(data1 == data2);
CHECK(data2 == data1);
data1 = Data("Data1");
data2 = Data("Data2");
CHECK(!(data1 == data2));
CHECK(!(data2 == data1));
CHECK(!(etl::nullopt == data2));
CHECK(!(data1 == etl::nullopt));
CHECK(data1 == Data("Data1"));
CHECK(!(data1 == Data("Data2")));
CHECK(Data("Data1") == data1);
CHECK(!(Data("Data2") == data1));
}
//*************************************************************************
TEST(test_inequality)
{
etl::optional<Data> data1;
etl::optional<Data> data2;
CHECK(!(data1 != data2));
CHECK(!(data2 != data1));
data1 = Data("Data1");
CHECK(data1 != data2);
CHECK(data2 != data1);
data1 = etl::nullopt;
data2 = Data("Data2");
CHECK(data1 != data2);
CHECK(data2 != data1);
data1 = Data("Data1");
data2 = Data("Data1");
CHECK(!(data1 != data2));
CHECK(!(data2 != data1));
data1 = Data("Data1");
data2 = Data("Data2");
CHECK(data1 != data2);
CHECK(data2 != data1);
CHECK(etl::nullopt != data2);
CHECK(data1 != etl::nullopt);
CHECK(!(data1 != Data("Data1")));
CHECK(data1 != Data("Data2"));
CHECK(!(Data("Data1") != data1));
CHECK(Data("Data2") != data1);
}
// //*************************************************************************
// TEST(test_initialisation)
// {
// etl::optional<Data> data1;
// etl::optional<Data> data2;
//
// CHECK(!bool(data1));
// CHECK(!bool(data2));
// CHECK(!data1.has_value());
// CHECK(!data2.has_value());
//
// data1 = Data("Hello");
// CHECK(bool(data1));
// CHECK(data1.has_value());
// CHECK_EQUAL(Data("Hello"), data1);
//
// data1 = data2;
// CHECK(!bool(data1));
// CHECK(!bool(data2));
// CHECK(!data1.has_value());
// CHECK(!data2.has_value());
//
// data1 = Data("World");
// data2 = data1;
// CHECK(bool(data1));
// CHECK(bool(data2));
// CHECK(data1.has_value());
// CHECK(data2.has_value());
//
// etl::optional<Data> data3(data1);
// CHECK(bool(data3));
// CHECK(data3.has_value());
// CHECK_EQUAL(data1, data3);
//
// etl::optional<Data> data4;
// data4 = Data("Hello");
// data4 = etl::nullopt;
// CHECK(!bool(data4));
// CHECK(!data4.has_value());
// }
//
// //*************************************************************************
// TEST(test_deduced_initialisation)
// {
// Data data("Hello");
//
// etl::optional opt{ data };
//
// CHECK(opt.has_value());
// CHECK(bool(opt));
// CHECK_EQUAL(data, opt);
// }
//
// //*************************************************************************
// TEST(test_emplace)
// {
// etl::optional<DataM> data;
//
// data.emplace(1U);
// CHECK_EQUAL(1U, data.value().value);
//
// data.emplace(2U);
// CHECK_EQUAL(2U, data.value().value);
//
// data.emplace(3U);
// CHECK_EQUAL(3U, data.value().value);
//
// CHECK_EQUAL(1, DataM::get_instance_count());
// }
//
// //*************************************************************************
// TEST(test_moveable)
// {
//#include "etl/private/diagnostic_pessimizing_move_push.h"
// etl::optional<DataM> data(std::move(DataM(1)));
// CHECK_EQUAL(1U, data.value().value);
// CHECK(bool(data));
//
// data = std::move(etl::optional<DataM>(std::move(DataM(2))));
// CHECK_EQUAL(2U, data.value().value);
// CHECK(bool(data));
//
// etl::optional<DataM> data2(etl::move(data));
// CHECK_EQUAL(2U, data2.value().value);
// CHECK(bool(data2));
//#include "etl/private/diagnostic_pop.h"
// }
//
// //*************************************************************************
// TEST(test_nullopt)
// {
// etl::optional<Data> data;
// data = Data("Hello");
// data = etl::nullopt;
// CHECK(!bool(data));
// }
//
// //*************************************************************************
// TEST(test_value_or)
// {
// etl::optional<Data> data;
//
// Data result = data.value_or(Data("Default"));
// CHECK_EQUAL(Data("Default"), result);
//
// data = Data("Value");
// result = data.value_or(Data("Default"));
// CHECK_EQUAL(Data("Value"), result);
// }
//
// //*************************************************************************
// TEST(test_equality)
// {
// etl::optional<Data> data1;
// etl::optional<Data> data2;
//
// CHECK(data1 == data2);
// CHECK(data2 == data1);
//
// data1 = Data("Data1");
// CHECK(!(data1 == data2));
// CHECK(!(data2 == data1));
//
// data1 = etl::nullopt;
// data2 = Data("Data2");
// CHECK(!(data1 == data2));
// CHECK(!(data2 == data1));
//
// data1 = Data("Data1");
// data2 = Data("Data1");
// CHECK(data1 == data2);
// CHECK(data2 == data1);
//
// data1 = Data("Data1");
// data2 = Data("Data2");
// CHECK(!(data1 == data2));
// CHECK(!(data2 == data1));
//
// CHECK(!(etl::nullopt == data2));
// CHECK(!(data1 == etl::nullopt));
//
// CHECK(data1 == Data("Data1"));
// CHECK(!(data1 == Data("Data2")));
// CHECK(Data("Data1") == data1);
// CHECK(!(Data("Data2") == data1));
// }
//
// //*************************************************************************
// TEST(test_inequality)
// {
// etl::optional<Data> data1;
// etl::optional<Data> data2;
//
// CHECK(!(data1 != data2));
// CHECK(!(data2 != data1));
//
// data1 = Data("Data1");
// CHECK(data1 != data2);
// CHECK(data2 != data1);
//
// data1 = etl::nullopt;
// data2 = Data("Data2");
// CHECK(data1 != data2);
// CHECK(data2 != data1);
//
// data1 = Data("Data1");
// data2 = Data("Data1");
// CHECK(!(data1 != data2));
// CHECK(!(data2 != data1));
//
// data1 = Data("Data1");
// data2 = Data("Data2");
// CHECK(data1 != data2);
// CHECK(data2 != data1);
//
// CHECK(etl::nullopt != data2);
// CHECK(data1 != etl::nullopt);
//
// CHECK(!(data1 != Data("Data1")));
// CHECK(data1 != Data("Data2"));
// CHECK(!(Data("Data1") != data1));
// CHECK(Data("Data2") != data1);
// }
//*************************************************************************
//#include "etl/private/diagnostic_uninitialized_push.h"
TEST(test_less_than)
{
etl::optional<Data> data1;
etl::optional<Data> data2;
struct S
{
std::string str;
};
CHECK(!(data2 < data1));
CHECK(!(data1 < data2));
etl::optional<S> data1;
etl::optional<S> data2;
data1 = Data("Data1");
CHECK(!(data1 < data2));
CHECK(data2 < data1);
//CHECK(!(data2 < data1));
//CHECK(!(data1 < data2));
data1 = etl::nullopt;
data2 = Data("Data2");
CHECK(data1 < data2);
CHECK(!(data2 < data2));
//data1 = Data("Data1");
//CHECK(!(data1 < data2));
//CHECK(data2 < data1);
data1 = Data("Data1");
data2 = Data("Data2");
CHECK(data1 < data2);
CHECK(!(data2 < data1));
//data1 = etl::nullopt;
//data2 = Data("Data2");
//CHECK(data1 < data2);
//CHECK(!(data2 < data2));
CHECK(etl::nullopt < data2);
CHECK(!(data1 < etl::nullopt));
//data1 = Data("Data1");
//data2 = Data("Data2");
//CHECK(data1 < data2);
//CHECK(!(data2 < data1));
CHECK(data1 < Data("Data2"));
CHECK(!(data1 < Data("Data1")));
CHECK(!(Data("Data2") < data1));
CHECK(Data("Data1") < data2);
//CHECK(etl::nullopt < data2);
//CHECK(!(data1 < etl::nullopt));
//CHECK(data1 < Data("Data2"));
//CHECK(!(data1 < Data("Data1")));
//CHECK(!(Data("Data2") < data1));
//CHECK(Data("Data1") < data2);
}
//#include "etl/private/diagnostic_pop.h"
//*************************************************************************
TEST(test_less_than_equal)
{
etl::optional<Data> data1;
etl::optional<Data> data2;
CHECK(data1 <= data2);
CHECK(data2 <= data1);
data1 = Data("Data1");
CHECK(!(data1 <= data2));
CHECK(data2 <= data1);
data1 = etl::nullopt;
data2 = Data("Data2");
CHECK(data1 <= data2);
CHECK(!(data2 <= data1));
data1 = Data("Data1");
data2 = Data("Data2");
CHECK(data1 <= data2);
CHECK(!(data2 <= data1));
CHECK(etl::nullopt <= data2);
CHECK(!(data1 <= etl::nullopt));
CHECK(data1 <= Data("Data2"));
CHECK(!(data2 <= Data("Data1")));
CHECK(data1 <= Data("Data1"));
CHECK(!(Data("Data2") <= data1));
CHECK(Data("Data1") <= data2);
CHECK(Data("Data1") <= data1);
}
//*************************************************************************
TEST(test_greater_than)
{
etl::optional<Data> data1;
etl::optional<Data> data2;
CHECK(!(data1 > data2));
CHECK(!(data2 > data1));
data1 = Data("Data1");
CHECK(data1 > data2);
CHECK(!(data2 > data1));
data1 = etl::nullopt;
data2 = Data("Data2");
CHECK(!(data1 > data2));
CHECK(data2 > data1);
data1 = Data("Data1");
data2 = Data("Data2");
CHECK(data2 > data1);
CHECK(!(data1 > data2));
CHECK(!(etl::nullopt > data2));
CHECK(data1 > etl::nullopt);
CHECK(!(data1 > Data("Data2")));
CHECK(data2 > Data("Data1"));
CHECK(Data("Data2") > data1);
CHECK(!(Data("Data1") > data2));
}
//*************************************************************************
TEST(test_greater_than_equal)
{
etl::optional<Data> data1;
etl::optional<Data> data2;
CHECK(data1 >= data2);
CHECK(data2 >= data1);
data1 = Data("Data1");
CHECK(data1 >= data2);
CHECK(!(data2 >= data1));
data1 = etl::nullopt;
data2 = Data("Data2");
CHECK(!(data1 >= data2));
CHECK(data2 >= data1);
data1 = Data("Data1");
data2 = Data("Data2");
CHECK(!(data1 >= data2));
CHECK(data2 >= data1);
CHECK(!(etl::nullopt >= data2));
CHECK(data1 >= etl::nullopt);
CHECK(!(data1 >= Data("Data2")));
CHECK(data2 >= Data("Data1"));
CHECK(data1 >= Data("Data1"));
CHECK(Data("Data2") >= data1);
CHECK(!(Data("Data1") >= data2));
CHECK(Data("Data1") >= data1);
}
//*************************************************************************
TEST(test_container_of_optional)
{
etl::vector<etl::optional<Data>, 10> container;
container.resize(5, Data("1"));
CHECK(bool(container[0]));
CHECK(bool(container[1]));
CHECK(bool(container[2]));
CHECK(bool(container[3]));
CHECK(bool(container[4]));
}
//*************************************************************************
TEST(test_optional_container)
{
// The indexed access doesn't work in Linux for some reason!!!
#ifndef ETL_PLATFORM_LINUX
etl::optional<etl::vector<Data, 10>> container;
CHECK(!bool(container));//
container = etl::vector<Data, 10>();
CHECK(bool(container));
container.value().resize(5, Data("1"));
CHECK_EQUAL(5U, container.value().size());
CHECK_EQUAL(Data("1"), container.value()[0]);
CHECK_EQUAL(Data("1"), container.value()[1]);
CHECK_EQUAL(Data("1"), container.value()[2]);
CHECK_EQUAL(Data("1"), container.value()[3]);
CHECK_EQUAL(Data("1"), container.value()[4]);
#endif
}
// //*************************************************************************
// TEST(test_less_than_equal)
// {
// etl::optional<Data> data1;
// etl::optional<Data> data2;
//
// CHECK(data1 <= data2);
// CHECK(data2 <= data1);
//
// data1 = Data("Data1");
// CHECK(!(data1 <= data2));
// CHECK(data2 <= data1);
//
// data1 = etl::nullopt;
// data2 = Data("Data2");
// CHECK(data1 <= data2);
// CHECK(!(data2 <= data1));
//
// data1 = Data("Data1");
// data2 = Data("Data2");
// CHECK(data1 <= data2);
// CHECK(!(data2 <= data1));
//
// CHECK(etl::nullopt <= data2);
// CHECK(!(data1 <= etl::nullopt));
//
// CHECK(data1 <= Data("Data2"));
// CHECK(!(data2 <= Data("Data1")));
// CHECK(data1 <= Data("Data1"));
// CHECK(!(Data("Data2") <= data1));
// CHECK(Data("Data1") <= data2);
// CHECK(Data("Data1") <= data1);
// }
//
// //*************************************************************************
// TEST(test_greater_than)
// {
// etl::optional<Data> data1;
// etl::optional<Data> data2;
//
// CHECK(!(data1 > data2));
// CHECK(!(data2 > data1));
//
// data1 = Data("Data1");
// CHECK(data1 > data2);
// CHECK(!(data2 > data1));
//
// data1 = etl::nullopt;
// data2 = Data("Data2");
// CHECK(!(data1 > data2));
// CHECK(data2 > data1);
//
// data1 = Data("Data1");
// data2 = Data("Data2");
// CHECK(data2 > data1);
// CHECK(!(data1 > data2));
//
// CHECK(!(etl::nullopt > data2));
// CHECK(data1 > etl::nullopt);
//
// CHECK(!(data1 > Data("Data2")));
// CHECK(data2 > Data("Data1"));
// CHECK(Data("Data2") > data1);
// CHECK(!(Data("Data1") > data2));
// }
//
// //*************************************************************************
// TEST(test_greater_than_equal)
// {
// etl::optional<Data> data1;
// etl::optional<Data> data2;
//
// CHECK(data1 >= data2);
// CHECK(data2 >= data1);
//
// data1 = Data("Data1");
// CHECK(data1 >= data2);
// CHECK(!(data2 >= data1));
//
// data1 = etl::nullopt;
// data2 = Data("Data2");
// CHECK(!(data1 >= data2));
// CHECK(data2 >= data1);
//
// data1 = Data("Data1");
// data2 = Data("Data2");
// CHECK(!(data1 >= data2));
// CHECK(data2 >= data1);
//
// CHECK(!(etl::nullopt >= data2));
// CHECK(data1 >= etl::nullopt);
//
// CHECK(!(data1 >= Data("Data2")));
// CHECK(data2 >= Data("Data1"));
// CHECK(data1 >= Data("Data1"));
// CHECK(Data("Data2") >= data1);
// CHECK(!(Data("Data1") >= data2));
// CHECK(Data("Data1") >= data1);
// }
//
// //*************************************************************************
// TEST(test_container_of_optional)
// {
// etl::vector<etl::optional<Data>, 10> container;
//
// container.resize(5, Data("1"));
//
// CHECK(bool(container[0]));
// CHECK(bool(container[1]));
// CHECK(bool(container[2]));
// CHECK(bool(container[3]));
// CHECK(bool(container[4]));
// }
//
// //*************************************************************************
// TEST(test_optional_container)
// {
// // The indexed access doesn't work in Linux for some reason!!!
//#ifndef ETL_PLATFORM_LINUX
// etl::optional<etl::vector<Data, 10>> container;
// CHECK(!bool(container));//
//
// container = etl::vector<Data, 10>();
// CHECK(bool(container));
//
// container.value().resize(5, Data("1"));
// CHECK_EQUAL(5U, container.value().size());
//
// CHECK_EQUAL(Data("1"), container.value()[0]);
// CHECK_EQUAL(Data("1"), container.value()[1]);
// CHECK_EQUAL(Data("1"), container.value()[2]);
// CHECK_EQUAL(Data("1"), container.value()[3]);
// CHECK_EQUAL(Data("1"), container.value()[4]);
//#endif
// }
//*************************************************************************
TEST(test_exception)
{
etl::optional<Data> data1;
CHECK_THROW(Data d(data1.value()), etl::optional_invalid);
CHECK_THROW(data1.value(), etl::optional_invalid);
}
//*************************************************************************
TEST(test_swap)
{
etl::optional<Data> original1(Data("1"));
etl::optional<Data> original2(Data("2"));
////*************************************************************************
//TEST(test_swap)
//{
// etl::optional<Data> original1(Data("1"));
// etl::optional<Data> original2(Data("2"));
etl::optional<Data> data1;
etl::optional<Data> data2;
// etl::optional<Data> data1;
// etl::optional<Data> data2;
// Both invalid.
swap(data1, data2);
CHECK(!bool(data1));
CHECK(!bool(data2));
// // Both invalid.
// swap(data1, data2);
// CHECK(!bool(data1));
// CHECK(!bool(data2));
// Data1 valid;
data1 = original1;
data2 = etl::nullopt;
swap(data1, data2);
CHECK(!bool(data1));
CHECK(bool(data2));
CHECK_EQUAL(data2, original1);
// // Data1 valid;
// data1 = original1;
// data2 = etl::nullopt;
// swap(data1, data2);
// CHECK(!bool(data1));
// CHECK(bool(data2));
// CHECK_EQUAL(data2, original1);
// Data2 valid;
data1 = etl::nullopt;
data2 = original2;
swap(data1, data2);
CHECK(bool(data1));
CHECK(!bool(data2));
CHECK_EQUAL(data1, original2);
// // Data2 valid;
// data1 = etl::nullopt;
// data2 = original2;
// swap(data1, data2);
// CHECK(bool(data1));
// CHECK(!bool(data2));
// CHECK_EQUAL(data1, original2);
// Both valid;
data1 = original1;
data2 = original2;
swap(data1, data2);
CHECK(bool(data1));
CHECK(bool(data2));
CHECK_EQUAL(data1, original2);
CHECK_EQUAL(data2, original1);
}
// // Both valid;
// data1 = original1;
// data2 = original2;
// swap(data1, data2);
// CHECK(bool(data1));
// CHECK(bool(data2));
// CHECK_EQUAL(data1, original2);
// CHECK_EQUAL(data2, original1);
//}
//*************************************************************************
TEST(test_reset)
{
etl::optional<Data> data(Data("1"));
CHECK(bool(data));
////*************************************************************************
//TEST(test_reset)
//{
// etl::optional<Data> data(Data("1"));
// CHECK(bool(data));
data.reset();
CHECK(!bool(data));
}
// data.reset();
// CHECK(!bool(data));
//}
//*************************************************************************
etl::optional<std::uint8_t> get_optional_test_bug_634()
{
etl::optional<std::uint8_t> result = 8;
result.reset();
return result;
}
////*************************************************************************
//etl::optional<std::uint8_t> get_optional_test_bug_634()
//{
// etl::optional<std::uint8_t> result = 8;
// result.reset();
//
// return result;
//}
TEST(test_bug_634)
{
etl::optional<std::uint8_t> result;
//TEST(test_bug_634)
//{
// etl::optional<std::uint8_t> result;
result = get_optional_test_bug_634();
// result = get_optional_test_bug_634();
CHECK_EQUAL(false, result.has_value());
}
// CHECK_EQUAL(false, result.has_value());
//}
//*************************************************************************
TEST(test_optional_emplace_bug_636)
{
etl::optional<std::uint8_t> result = 1;
result.emplace(2);
////*************************************************************************
//TEST(test_optional_emplace_bug_636)
//{
// etl::optional<std::uint8_t> result = 1;
// result.emplace(2);
CHECK_TRUE(result.has_value());
CHECK_EQUAL(2, result.value());
}
// CHECK_TRUE(result.has_value());
// CHECK_EQUAL(2, result.value());
//}
};
}

View File

@ -41,6 +41,8 @@ Global
Debug MSVC|x64 = Debug MSVC|x64
Debug|Win32 = Debug|Win32
Debug|x64 = Debug|x64
MSVC - No STL -O2|Win32 = MSVC - No STL -O2|Win32
MSVC - No STL -O2|x64 = MSVC - No STL -O2|x64
MSVC Debug Appveyor|Win32 = MSVC Debug Appveyor|Win32
MSVC Debug Appveyor|x64 = MSVC Debug Appveyor|x64
MSVC Debug No STL Appveyor|Win32 = MSVC Debug No STL Appveyor|Win32
@ -117,6 +119,10 @@ Global
{C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.Debug|Win32.Build.0 = Debug|Win32
{C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.Debug|x64.ActiveCfg = Debug|x64
{C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.Debug|x64.Build.0 = Debug|x64
{C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.MSVC - No STL -O2|Win32.ActiveCfg = MSVC - No STL -O2|Win32
{C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.MSVC - No STL -O2|Win32.Build.0 = MSVC - No STL -O2|Win32
{C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.MSVC - No STL -O2|x64.ActiveCfg = MSVC - No STL -O2|x64
{C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.MSVC - No STL -O2|x64.Build.0 = MSVC - No STL -O2|x64
{C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.MSVC Debug Appveyor|Win32.ActiveCfg = Debug|Win32
{C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.MSVC Debug Appveyor|Win32.Build.0 = Debug|Win32
{C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.MSVC Debug Appveyor|x64.ActiveCfg = MSVC Debug Appveyor|x64

File diff suppressed because it is too large Load Diff

View File

@ -1305,9 +1305,6 @@
<ClInclude Include="..\etl_error_handler\exceptions\etl_profile.h">
<Filter>Tests\Error Handler\Exceptions</Filter>
</ClInclude>
<ClInclude Include="..\etl_error_handler\exceptions_and_log_errors\etl_profile.h">
<Filter>Tests\Error Handler\Exceptions_And_Log_Errors</Filter>
</ClInclude>
<ClInclude Include="..\..\include\etl\private\diagnostic_pop.h">
<Filter>ETL\Private</Filter>
</ClInclude>
@ -1344,6 +1341,9 @@
<ClInclude Include="..\..\include\etl\expected.h">
<Filter>ETL\Containers</Filter>
</ClInclude>
<ClInclude Include="..\etl_error_handler\log_errors_and_exceptions\etl_profile.h">
<Filter>Tests\Error Handler\Exceptions_And_Log_Errors</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\test_string_char.cpp">
@ -3344,9 +3344,6 @@
<ClCompile Include="..\etl_error_handler\exceptions\test_error_handler.cpp">
<Filter>Tests\Error Handler\Exceptions</Filter>
</ClCompile>
<ClCompile Include="..\etl_error_handler\exceptions_and_log_errors\test_error_handler.cpp">
<Filter>Tests\Error Handler\Exceptions_And_Log_Errors</Filter>
</ClCompile>
<ClCompile Include="..\test_message_broker.cpp">
<Filter>Tests\Messaging</Filter>
</ClCompile>
@ -3392,6 +3389,9 @@
<ClCompile Include="..\sanity-check\to_arithmetic.h.t.cpp">
<Filter>Tests\Sanity Checks\Source</Filter>
</ClCompile>
<ClCompile Include="..\etl_error_handler\log_errors_and_exceptions\test_error_handler.cpp">
<Filter>Tests\Error Handler\Exceptions_And_Log_Errors</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="..\..\library.properties">
@ -3543,7 +3543,7 @@
<Text Include="..\etl_error_handler\exceptions\CMakeLists.txt">
<Filter>Tests\Error Handler\Exceptions</Filter>
</Text>
<Text Include="..\etl_error_handler\exceptions_and_log_errors\CMakeLists.txt">
<Text Include="..\etl_error_handler\log_errors_and_exceptions\CMakeLists.txt">
<Filter>Tests\Error Handler\Exceptions_And_Log_Errors</Filter>
</Text>
</ItemGroup>