diff --git a/libuavcan/include/uavcan/internal/impl_constants.hpp b/libuavcan/include/uavcan/internal/impl_constants.hpp index 48df88a375..f10a6cb3f0 100644 --- a/libuavcan/include/uavcan/internal/impl_constants.hpp +++ b/libuavcan/include/uavcan/internal/impl_constants.hpp @@ -9,6 +9,15 @@ namespace uavcan { +/** + * UAVCAN can be explicitly told to ignore exceptions, or it can be detected automatically. + */ +#ifndef UAVCAN_EXCEPTIONS +# if defined(__EXCEPTIONS) || defined(_HAS_EXCEPTIONS) +# define UAVCAN_EXCEPTIONS 1 +# endif +#endif + /** * Should be OK for any target arch up to AMD64 and any compiler. * The library leverages compile-time checks to ensure that all types that are subject to dynamic allocation diff --git a/libuavcan/include/uavcan/internal/marshalling/float_spec.hpp b/libuavcan/include/uavcan/internal/marshalling/float_spec.hpp index cdda4ff843..aa7e29240e 100644 --- a/libuavcan/include/uavcan/internal/marshalling/float_spec.hpp +++ b/libuavcan/include/uavcan/internal/marshalling/float_spec.hpp @@ -107,12 +107,10 @@ public: using IEEE754Limits::max; using IEEE754Limits::epsilon; - static StorageType init() { return 0.0; } static std::float_round_style roundstyle() { return IEEE754Converter::roundstyle(); } - static int encode(StorageType value, ScalarCodec& codec, bool enable_tail_array_optimization = false) + static int encode(StorageType value, ScalarCodec& codec) { - (void)enable_tail_array_optimization; // cppcheck-suppress duplicateExpression if (CastMode == CastModeSaturate) saturate(value); @@ -121,9 +119,8 @@ public: return codec.encode(IEEE754Converter::toIeee(value)); } - static int decode(StorageType& out_value, ScalarCodec& codec, bool enable_tail_array_optimization = false) + static int decode(StorageType& out_value, ScalarCodec& codec) { - (void)enable_tail_array_optimization; typename IntegerSpec::StorageType ieee = 0; const int res = codec.decode(ieee); if (res <= 0) diff --git a/libuavcan/include/uavcan/internal/marshalling/integer_spec.hpp b/libuavcan/include/uavcan/internal/marshalling/integer_spec.hpp index b0121ded64..0559adf8d6 100644 --- a/libuavcan/include/uavcan/internal/marshalling/integer_spec.hpp +++ b/libuavcan/include/uavcan/internal/marshalling/integer_spec.hpp @@ -77,11 +77,8 @@ public: // cppcheck-suppress duplicateExpression static StorageType min() { return Limits::min(); } - static StorageType init() { return 0; } - - static int encode(StorageType value, ScalarCodec& codec, bool enable_tail_array_optimization = false) + static int encode(StorageType value, ScalarCodec& codec) { - (void)enable_tail_array_optimization; // cppcheck-suppress duplicateExpression if (CastMode == CastModeSaturate) saturate(value); @@ -90,9 +87,8 @@ public: return codec.encode(value); } - static int decode(StorageType& out_value, ScalarCodec& codec, bool enable_tail_array_optimization = false) + static int decode(StorageType& out_value, ScalarCodec& codec) { - (void)enable_tail_array_optimization; return codec.decode(out_value); } }; diff --git a/libuavcan/include/uavcan/internal/util.hpp b/libuavcan/include/uavcan/internal/util.hpp index 2e074c8e4d..b2ffc03e1e 100644 --- a/libuavcan/include/uavcan/internal/util.hpp +++ b/libuavcan/include/uavcan/internal/util.hpp @@ -64,4 +64,11 @@ struct StaticIf }; +template struct BooleanType { }; +typedef BooleanType TrueType; +typedef BooleanType FalseType; + } + +/// Ensure that conditional comilation macros are present +#include diff --git a/libuavcan/test/marshalling/float_spec.cpp b/libuavcan/test/marshalling/float_spec.cpp index 71595a37a3..1cd1eba23c 100644 --- a/libuavcan/test/marshalling/float_spec.cpp +++ b/libuavcan/test/marshalling/float_spec.cpp @@ -21,17 +21,14 @@ TEST(FloatSpec, Limits) typedef FloatSpec<64, CastModeTruncate> F64T; ASSERT_FALSE(F16S::IsExactRepresentation); - ASSERT_EQ(0, F16S::init()); ASSERT_FLOAT_EQ(65504.0, F16S::max()); ASSERT_FLOAT_EQ(9.77e-04, F16S::epsilon()); ASSERT_TRUE(F32T::IsExactRepresentation); - ASSERT_EQ(0, F32T::init()); ASSERT_FLOAT_EQ(std::numeric_limits::max(), F32T::max()); ASSERT_FLOAT_EQ(std::numeric_limits::epsilon(), F32T::epsilon()); ASSERT_TRUE(F64S::IsExactRepresentation); - ASSERT_EQ(0, F64S::init()); ASSERT_FLOAT_EQ(std::numeric_limits::max(), F64S::max()); ASSERT_FLOAT_EQ(std::numeric_limits::epsilon(), F64S::epsilon()); } @@ -125,7 +122,7 @@ TEST(FloatSpec, Basic) #define CHECK(FloatType, expected_value) \ do { \ - StorageType::Type var(FloatType::init()); \ + StorageType::Type var = StorageType::Type(); \ ASSERT_EQ(1, FloatType::decode(var, sc_rd)); \ if (!isnan(expected_value)) \ ASSERT_FLOAT_EQ(expected_value, var); \ diff --git a/libuavcan/test/marshalling/integer_spec.cpp b/libuavcan/test/marshalling/integer_spec.cpp index dbf1d690c5..cd63e2ffc9 100644 --- a/libuavcan/test/marshalling/integer_spec.cpp +++ b/libuavcan/test/marshalling/integer_spec.cpp @@ -88,7 +88,7 @@ TEST(IntegerSpec, Basic) #define CHECK(IntType, expected_value) \ do { \ - StorageType::Type var(IntType::init()); \ + StorageType::Type var = StorageType::Type(); \ ASSERT_EQ(1, IntType::decode(var, sc_rd)); \ ASSERT_EQ(expected_value, var); \ } while (0)