mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-11-02 06:51:36 +08:00
-Wold-style-cast; linked list items made noncopyable
This commit is contained in:
@@ -123,8 +123,9 @@ if (DEBUG_BUILD)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror -pedantic -Wfloat-equal -Wconversion")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wsign-conversion -Wcast-align -Wmissing-declarations -Wlogical-op")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wdouble-promotion -Wswitch-enum -Wtype-limits -Wno-error=array-bounds")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wzero-as-null-pointer-constant -Wnon-virtual-dtor -Woverloaded-virtual")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wsign-promo")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wzero-as-null-pointer-constant -Wnon-virtual-dtor")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Woverloaded-virtual -Wsign-promo -Wold-style-cast")
|
||||
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Weffc++ -Wno-error=effc++") # Produces heaps of useless warnings
|
||||
set(cpp03_flags "-std=c++03 -Wno-variadic-macros -Wno-long-long -Wno-zero-as-null-pointer-constant")
|
||||
set(optim_flags "-O3 -DNDEBUG -g0")
|
||||
else ()
|
||||
|
||||
@@ -761,7 +761,8 @@ public:
|
||||
* Members must be comparable via operator ==.
|
||||
*/
|
||||
template <typename R>
|
||||
typename EnableIf<sizeof(((const R*)(0U))->size()) && sizeof((*((const R*)(0U)))[0]), bool>::Type
|
||||
typename EnableIf<sizeof((reinterpret_cast<const R*>(0))->size()) &&
|
||||
sizeof((*(reinterpret_cast<const R*>(0)))[0]), bool>::Type
|
||||
operator==(const R& rhs) const
|
||||
{
|
||||
if (size() != rhs.size())
|
||||
@@ -786,7 +787,8 @@ public:
|
||||
* Any container with size() and [] is acceptable.
|
||||
*/
|
||||
template <typename R>
|
||||
typename EnableIf<sizeof(((const R*)(0U))->size()) && sizeof((*((const R*)(0U)))[0]), bool>::Type
|
||||
typename EnableIf<sizeof((reinterpret_cast<const R*>(0))->size()) &&
|
||||
sizeof((*(reinterpret_cast<const R*>(0)))[0]), bool>::Type
|
||||
isClose(const R& rhs) const
|
||||
{
|
||||
if (size() != rhs.size())
|
||||
@@ -1001,7 +1003,8 @@ public:
|
||||
* Note that matrix packing code uses @ref areClose() for comparison.
|
||||
*/
|
||||
template <typename R>
|
||||
typename EnableIf<sizeof(((const R*)(0U))->begin()) && sizeof(((const R*)(0U))->size())>::Type
|
||||
typename EnableIf<sizeof((reinterpret_cast<const R*>(0))->begin()) &&
|
||||
sizeof((reinterpret_cast<const R*>(0))->size())>::Type
|
||||
packSquareMatrix(const R& src_row_major)
|
||||
{
|
||||
if (src_row_major.size() == MaxSize)
|
||||
@@ -1057,7 +1060,8 @@ public:
|
||||
* Please refer to the specification to learn more about matrix packing.
|
||||
*/
|
||||
template <typename R>
|
||||
typename EnableIf<sizeof(((const R*)(0U))->begin()) && sizeof(((const R*)(0U))->size())>::Type
|
||||
typename EnableIf<sizeof((reinterpret_cast<const R*>(0))->begin()) &&
|
||||
sizeof((reinterpret_cast<const R*>(0))->size())>::Type
|
||||
unpackSquareMatrix(R& dst_row_major) const
|
||||
{
|
||||
if (dst_row_major.size() == MaxSize)
|
||||
|
||||
@@ -211,7 +211,9 @@ GlobalDataTypeRegistry::RegistrationResult GlobalDataTypeRegistry::registerDataT
|
||||
{
|
||||
return RegistrationResultFrozen;
|
||||
}
|
||||
|
||||
static Entry entry;
|
||||
|
||||
{
|
||||
const RegistrationResult remove_res = remove(&entry);
|
||||
if (remove_res != RegistrationResultOk)
|
||||
@@ -219,7 +221,11 @@ GlobalDataTypeRegistry::RegistrationResult GlobalDataTypeRegistry::registerDataT
|
||||
return remove_res;
|
||||
}
|
||||
}
|
||||
entry = Entry(DataTypeKind(Type::DataTypeKind), id, Type::getDataTypeSignature(), Type::getDataTypeFullName());
|
||||
|
||||
// We can't just overwrite the entry itself because it's noncopyable
|
||||
entry.descriptor = DataTypeDescriptor(DataTypeKind(Type::DataTypeKind), id,
|
||||
Type::getDataTypeSignature(), Type::getDataTypeFullName());
|
||||
|
||||
{
|
||||
const RegistrationResult remove_res = remove(&entry);
|
||||
if (remove_res != RegistrationResultOk)
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace uavcan
|
||||
|
||||
class UAVCAN_EXPORT Scheduler;
|
||||
|
||||
class UAVCAN_EXPORT DeadlineHandler : public LinkedListNode<DeadlineHandler>, Noncopyable
|
||||
class UAVCAN_EXPORT DeadlineHandler : public LinkedListNode<DeadlineHandler>
|
||||
{
|
||||
MonotonicTime deadline_;
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ class UAVCAN_EXPORT Dispatcher;
|
||||
/**
|
||||
* Inherit this class to receive notifications about all TX CAN frames that were transmitted with the loopback flag.
|
||||
*/
|
||||
class UAVCAN_EXPORT LoopbackFrameListenerBase : public LinkedListNode<LoopbackFrameListenerBase>, Noncopyable
|
||||
class UAVCAN_EXPORT LoopbackFrameListenerBase : public LinkedListNode<LoopbackFrameListenerBase>
|
||||
{
|
||||
Dispatcher& dispatcher_;
|
||||
|
||||
|
||||
@@ -96,7 +96,7 @@ public:
|
||||
/**
|
||||
* Internal, refer to the transport dispatcher class.
|
||||
*/
|
||||
class UAVCAN_EXPORT TransferListener : public LinkedListNode<TransferListener>, Noncopyable
|
||||
class UAVCAN_EXPORT TransferListener : public LinkedListNode<TransferListener>
|
||||
{
|
||||
const DataTypeDescriptor& data_type_;
|
||||
TransferBufferManager bufmgr_;
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include <cstdlib>
|
||||
#include <cassert>
|
||||
#include <uavcan/build_config.hpp>
|
||||
#include <uavcan/util/templates.hpp>
|
||||
|
||||
namespace uavcan
|
||||
{
|
||||
@@ -16,7 +17,7 @@ namespace uavcan
|
||||
* Classes that are supposed to be linked-listed should derive this.
|
||||
*/
|
||||
template <typename T>
|
||||
class UAVCAN_EXPORT LinkedListNode
|
||||
class UAVCAN_EXPORT LinkedListNode : Noncopyable
|
||||
{
|
||||
T* next_;
|
||||
|
||||
@@ -40,7 +41,7 @@ public:
|
||||
* Linked list root.
|
||||
*/
|
||||
template <typename T>
|
||||
class UAVCAN_EXPORT LinkedListRoot
|
||||
class UAVCAN_EXPORT LinkedListRoot : Noncopyable
|
||||
{
|
||||
T* root_;
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@ class UAVCAN_EXPORT Multiset : Noncopyable
|
||||
};
|
||||
|
||||
private:
|
||||
struct Chunk : LinkedListNode<Chunk>, ::uavcan::Noncopyable
|
||||
struct Chunk : LinkedListNode<Chunk>
|
||||
{
|
||||
enum { NumItems = (MemPoolBlockSize - sizeof(LinkedListNode<Chunk>)) / sizeof(Item) };
|
||||
Item items[NumItems];
|
||||
|
||||
@@ -28,7 +28,7 @@ void bitarrayCopy(const unsigned char* src, std::size_t src_offset, std::size_t
|
||||
|
||||
// The number of bits to copy
|
||||
const uint8_t max_offset = uavcan::max(src_bit_offset, dst_bit_offset);
|
||||
const std::size_t copy_bits = uavcan::min(last_bit - src_offset, (std::size_t)(8U - max_offset));
|
||||
const std::size_t copy_bits = uavcan::min(last_bit - src_offset, std::size_t(8U - max_offset));
|
||||
|
||||
/*
|
||||
* The mask indicating which bits of dest to update:
|
||||
|
||||
@@ -22,18 +22,18 @@ TEST(ScalarCodec, Basic)
|
||||
/*
|
||||
* Encoding some variables
|
||||
*/
|
||||
ASSERT_EQ(1, sc_wr.encode<12>((uint16_t)0xbeda)); // --> 0xeda
|
||||
ASSERT_EQ(1, sc_wr.encode<1>((uint8_t)1));
|
||||
ASSERT_EQ(1, sc_wr.encode<1>((uint16_t)0));
|
||||
ASSERT_EQ(1, sc_wr.encode<4>((uint8_t)8));
|
||||
ASSERT_EQ(1, sc_wr.encode<32>((uint32_t)0xdeadbeef));
|
||||
ASSERT_EQ(1, sc_wr.encode<3>((int8_t)-1));
|
||||
ASSERT_EQ(1, sc_wr.encode<4>((int8_t)-6));
|
||||
ASSERT_EQ(1, sc_wr.encode<20>((int32_t)-123456));
|
||||
ASSERT_EQ(1, sc_wr.encode<12>(uint16_t(0xbeda))); // --> 0xeda
|
||||
ASSERT_EQ(1, sc_wr.encode<1>(uint8_t(1)));
|
||||
ASSERT_EQ(1, sc_wr.encode<1>(uint16_t(0)));
|
||||
ASSERT_EQ(1, sc_wr.encode<4>(uint8_t(8)));
|
||||
ASSERT_EQ(1, sc_wr.encode<32>(uint32_t(0xdeadbeef)));
|
||||
ASSERT_EQ(1, sc_wr.encode<3>(int8_t(-1)));
|
||||
ASSERT_EQ(1, sc_wr.encode<4>(int8_t(-6)));
|
||||
ASSERT_EQ(1, sc_wr.encode<20>(int32_t(-123456)));
|
||||
ASSERT_EQ(1, sc_wr.encode<64>(std::numeric_limits<int64_t>::min()));
|
||||
ASSERT_EQ(1, sc_wr.encode<64>(std::numeric_limits<int64_t>::max()));
|
||||
ASSERT_EQ(1, sc_wr.encode<15>((int16_t)-1));
|
||||
ASSERT_EQ(1, sc_wr.encode<2>((int16_t)-1));
|
||||
ASSERT_EQ(1, sc_wr.encode<15>(int16_t(-1)));
|
||||
ASSERT_EQ(1, sc_wr.encode<2>(int16_t(-1)));
|
||||
ASSERT_EQ(1, sc_wr.encode<16>(std::numeric_limits<int16_t>::min()));
|
||||
ASSERT_EQ(1, sc_wr.encode<64>(std::numeric_limits<uint64_t>::max())); // Total 302 bit (38 bytes)
|
||||
|
||||
@@ -86,11 +86,11 @@ TEST(ScalarCodec, RepresentationCorrectness)
|
||||
uavcan::BitStream bs_wr(buf);
|
||||
uavcan::ScalarCodec sc_wr(bs_wr);
|
||||
|
||||
ASSERT_EQ(1, sc_wr.encode<12>((uint16_t)0xbeda)); // --> 0xeda
|
||||
ASSERT_EQ(1, sc_wr.encode<3>((int8_t)-1));
|
||||
ASSERT_EQ(1, sc_wr.encode<4>((int8_t)-5));
|
||||
ASSERT_EQ(1, sc_wr.encode<2>((int16_t)-1));
|
||||
ASSERT_EQ(1, sc_wr.encode<4>((uint8_t)0x88)); // --> 8
|
||||
ASSERT_EQ(1, sc_wr.encode<12>(uint16_t(0xbeda))); // --> 0xeda
|
||||
ASSERT_EQ(1, sc_wr.encode<3>(int8_t(-1)));
|
||||
ASSERT_EQ(1, sc_wr.encode<4>(int8_t(-5)));
|
||||
ASSERT_EQ(1, sc_wr.encode<2>(int16_t(-1)));
|
||||
ASSERT_EQ(1, sc_wr.encode<4>(uint8_t(0x88))); // --> 8
|
||||
|
||||
// This representation was carefully crafted and triple checked:
|
||||
static const std::string REFERENCE = "11011010 11101111 01111100 00000000";
|
||||
|
||||
@@ -37,7 +37,7 @@ TEST(Frame, MessageParseCompile)
|
||||
* Parse
|
||||
*/
|
||||
// Invalid CAN frames
|
||||
ASSERT_FALSE(frame.parse(CanFrame(can_id | CanFrame::FlagRTR, (const uint8_t*)"", 0)));
|
||||
ASSERT_FALSE(frame.parse(CanFrame(can_id | CanFrame::FlagRTR, reinterpret_cast<const uint8_t*>(""), 0)));
|
||||
ASSERT_FALSE(frame.parse(makeCanFrame(can_id, payload_string, STD)));
|
||||
|
||||
// Valid
|
||||
@@ -119,7 +119,7 @@ TEST(Frame, ServiceParseCompile)
|
||||
* Parse
|
||||
*/
|
||||
// Invalid CAN frames
|
||||
ASSERT_FALSE(frame.parse(CanFrame(can_id | CanFrame::FlagRTR, (const uint8_t*)"", 0)));
|
||||
ASSERT_FALSE(frame.parse(CanFrame(can_id | CanFrame::FlagRTR, reinterpret_cast<const uint8_t*>(""), 0)));
|
||||
ASSERT_FALSE(frame.parse(makeCanFrame(can_id, payload_string, STD)));
|
||||
|
||||
// Valid
|
||||
|
||||
@@ -102,7 +102,11 @@ TEST(LinkedList, Basic)
|
||||
TEST(LinkedList, Sorting)
|
||||
{
|
||||
uavcan::LinkedListRoot<ListItem> root;
|
||||
ListItem items[] = {0, 1, 2, 3, 4, 5};
|
||||
ListItem items[6];
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
items[i].value = i;
|
||||
}
|
||||
|
||||
EXPECT_EQ(0, root.getLength());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user