Skip to content

Commit 04f929e

Browse files
committed
MbedCRC.h: declare table specialisations
Clang emits warnings if it can see a declaration when it needs a templated variable. Add declarations for the specialisations in MbedCRC.cpp to MbedCRC.h keep it quiet. Tighten up a little by making all `_crc_table` references conditional on tables being configured on.
1 parent b77f6b4 commit 04f929e

File tree

1 file changed

+28
-5
lines changed

1 file changed

+28
-5
lines changed

drivers/MbedCRC.h

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -479,11 +479,10 @@ class MbedCRC {
479479
>>;
480480
// *INDENT-ON*
481481

482-
/* Not [MBED_CRC_TABLE_SIZE] as that could be [0], which is illegal.
483-
* We do need the declaration to always exist so that do_compute_partial<TABLE> is always well-formed,
484-
* but we never actually use it MBED_CRC_TABLE_SIZE is 0.
485-
*/
486-
static const crc_table_t _crc_table[];
482+
#if MBED_CRC_TABLE_SIZE > 0
483+
/* Tables only actually defined for mode == TABLE, and certain polynomials - see below */
484+
static const crc_table_t _crc_table[MBED_CRC_TABLE_SIZE];
485+
#endif
487486

488487
static uint32_t adjust_initial_value(uint32_t initial_xor, bool reflect_data)
489488
{
@@ -742,6 +741,7 @@ class MbedCRC {
742741
return 0;
743742
}
744743

744+
#if MBED_CRC_TABLE_SIZE > 0
745745
/** CRC computation using ROM tables.
746746
*
747747
* @param buffer data buffer
@@ -774,6 +774,7 @@ class MbedCRC {
774774
*crc = p_crc;
775775
return 0;
776776
}
777+
#endif
777778

778779
#ifdef DEVICE_CRC
779780
/** Hardware CRC computation.
@@ -793,6 +794,28 @@ class MbedCRC {
793794

794795
};
795796

797+
#if MBED_CRC_TABLE_SIZE > 0
798+
/* Declarations of the tables we provide. (Not strictly needed, but compilers
799+
* can warn if they see us using the template without a generic definition, so
800+
* let it know we have provided these specialisations.)
801+
*/
802+
template<>
803+
const uint8_t MbedCRC<POLY_7BIT_SD, 7, CrcMode::TABLE>::_crc_table[MBED_CRC_TABLE_SIZE];
804+
805+
template<>
806+
const uint8_t MbedCRC<POLY_8BIT_CCITT, 8, CrcMode::TABLE>::_crc_table[MBED_CRC_TABLE_SIZE];
807+
808+
template<>
809+
const uint16_t MbedCRC<POLY_16BIT_CCITT, 16, CrcMode::TABLE>::_crc_table[MBED_CRC_TABLE_SIZE];
810+
811+
template<>
812+
const uint16_t MbedCRC<POLY_16BIT_IBM, 16, CrcMode::TABLE>::_crc_table[MBED_CRC_TABLE_SIZE];
813+
814+
template<>
815+
const uint32_t MbedCRC<POLY_32BIT_ANSI, 32, CrcMode::TABLE>::_crc_table[MBED_CRC_TABLE_SIZE];
816+
817+
#endif // MBED_CRC_TABLE_SIZE > 0
818+
796819
} // namespace impl
797820

798821
#endif // !defined(DOXYGEN_ONLY)

0 commit comments

Comments
 (0)