Skip to content

Commit b3f7d82

Browse files
committed
Added constexpr to CRC1
1 parent 14b50c6 commit b3f7d82

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

include/etl/crc1.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,19 @@ namespace etl
5252
};
5353

5454
//*********************************
55-
value_type initial() const
55+
ETL_CONSTEXPR14 value_type initial() const
5656
{
5757
return even_parity;
5858
}
5959

6060
//*********************************
61-
uint8_t add(int parity, uint8_t value) const
61+
ETL_CONSTEXPR14 uint8_t add(int parity, uint8_t value) const
6262
{
6363
return parity ^ etl::parity(value);
6464
}
6565

6666
//*********************************
67-
uint8_t final(uint8_t parity) const
67+
ETL_CONSTEXPR14 uint8_t final(uint8_t parity) const
6868
{
6969
return parity;
7070
}
@@ -83,7 +83,7 @@ namespace etl
8383
//*************************************************************************
8484
/// Default constructor.
8585
//*************************************************************************
86-
crc1()
86+
ETL_CONSTEXPR14 crc1()
8787
{
8888
this->reset();
8989
}
@@ -94,7 +94,7 @@ namespace etl
9494
/// \param end End of the range.
9595
//*************************************************************************
9696
template<typename TIterator>
97-
crc1(TIterator begin, const TIterator end)
97+
ETL_CONSTEXPR14 crc1(TIterator begin, const TIterator end)
9898
{
9999
this->reset();
100100
this->add(begin, end);

include/etl/frame_check_sequence.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ namespace etl
107107
//*************************************************************************
108108
/// Default constructor.
109109
//*************************************************************************
110-
ETL_CONSTEXPR14 frame_check_sequence() : frame_check()
110+
ETL_CONSTEXPR14 frame_check_sequence()
111+
: frame_check()
111112
{
112113
reset();
113114
}

test/test_crc1.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,17 @@ namespace
6666
CHECK_EQUAL(calculate_parity(data.begin(), data.end()), int(crc));
6767
}
6868

69+
#if ETL_USING_CPP14
70+
//*************************************************************************
71+
TEST(test_crc1_constructor_constexpr)
72+
{
73+
constexpr char data[] = "123456789";
74+
constexpr uint8_t crc = etl::crc1(data, data + 9);
75+
76+
CHECK_EQUAL(calculate_parity(data, data + 9), int(crc));
77+
}
78+
#endif
79+
6980
//*************************************************************************
7081
TEST(test_crc1_add_values)
7182
{

0 commit comments

Comments
 (0)