Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clang - removing some compiler errors for clang #8

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
164 changes: 93 additions & 71 deletions embxx/container/StaticQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,15 @@ class StaticQueueBase

protected:
typedef T ValueType;

public:
typedef
typename std::aligned_storage<
sizeof(ValueType),
std::alignment_of<ValueType>::value
>::type StorageType;

protected:
typedef StorageType* StorageTypePtr;
typedef const StorageType* ConstStorageTypePtr;
typedef std::size_t SizeType;
Expand Down Expand Up @@ -532,47 +536,7 @@ class StaticQueueBase
return invalidIter();
}

Iterator erase(Iterator pos)
{
GASSERT(pos != end());
GASSERT(!empty());
Pointer elem = &(*pos);
auto rangeOne = arrayOne();
auto rangeTwo = arrayTwo();

auto isInRangeFunc =
[](Pointer elemPtr, const LinearisedIteratorRange range) -> bool
{
return ((&(*range.first) <= elemPtr) && (elemPtr < &(*range.second)));
};

GASSERT(isInRangeFunc(elem, rangeOne) ||
isInRangeFunc(elem, rangeTwo));

if (isInRangeFunc(elem, rangeOne)) {
std::move_backward(rangeOne.first, elem, elem + 1);

popFront();
rangeOne = arrayOne();
if (isInRangeFunc(elem, rangeOne)) {
return pos + 1;
}

return begin();
}

if (isInRangeFunc(elem, rangeTwo)) {
std::move(elem + 1, rangeTwo.second, elem);
popBack();
if (!linearised()) {
return pos;
}
return end();
}

GASSERT(!"Invalid iterator is used");
return end();
}
Iterator erase(Iterator pos);

Iterator begin()
{
Expand Down Expand Up @@ -1207,6 +1171,48 @@ class StaticQueueBase<T>::Iterator :
}
};

template <typename T>
typename StaticQueueBase<T>::Iterator StaticQueueBase<T>::erase(typename StaticQueueBase<T>::Iterator pos)
{
GASSERT(pos != end());
GASSERT(!empty());
Pointer elem = &(*pos);
auto rangeOne = arrayOne();
auto rangeTwo = arrayTwo();

auto isInRangeFunc =
[](Pointer elemPtr, const LinearisedIteratorRange range) -> bool
{
return ((&(*range.first) <= elemPtr) && (elemPtr < &(*range.second)));
};

GASSERT(isInRangeFunc(elem, rangeOne) ||
isInRangeFunc(elem, rangeTwo));

if (isInRangeFunc(elem, rangeOne)) {
std::move_backward(rangeOne.first, elem, elem + 1);

popFront();
rangeOne = arrayOne();
if (isInRangeFunc(elem, rangeOne)) {
return pos + 1;
}

return begin();
}

if (isInRangeFunc(elem, rangeTwo)) {
std::move(elem + 1, rangeTwo.second, elem);
popBack();
if (!linearised()) {
return pos;
}
return end();
}

GASSERT(!"Invalid iterator is used");
return end();
}

template <typename TWrapperElemType, typename TQueueElemType>
class CastWrapperQueueBase : public StaticQueueBase<TQueueElemType>
Expand Down Expand Up @@ -1234,11 +1240,15 @@ class CastWrapperQueueBase : public StaticQueueBase<TQueueElemType>

protected:
typedef WrapperElemType ValueType;

public:
typedef
typename std::aligned_storage<
sizeof(ValueType),
std::alignment_of<ValueType>::value
>::type StorageType;

protected:
typedef StorageType* StorageTypePtr;
typedef ValueType& Reference;
typedef const ValueType& ConstReference;
Expand Down Expand Up @@ -1446,11 +1456,7 @@ class CastWrapperQueueBase : public StaticQueueBase<TQueueElemType>
reinterpret_cast<BaseLinearisedIterator>(pos)));
}

Iterator erase(Iterator pos)
{
auto tmp = Base::erase(pos);
return *(reinterpret_cast<Iterator*>(&tmp));
}
inline Iterator erase(Iterator pos);

Iterator begin()
{
Expand Down Expand Up @@ -1724,6 +1730,14 @@ class CastWrapperQueueBase<TWrapperElemType, TQueueElemType>::Iterator :
}
};

template <typename TWrapperElemType, typename TQueueElemType>
inline typename CastWrapperQueueBase<TWrapperElemType, TQueueElemType>::Iterator CastWrapperQueueBase<TWrapperElemType, TQueueElemType>::erase(
typename CastWrapperQueueBase<TWrapperElemType, TQueueElemType>::Iterator pos)
{
auto tmp = Base::erase(pos);
return *(reinterpret_cast<Iterator*>(&tmp));
}

template <typename T>
class StaticQueueBaseOptimised : public StaticQueueBase<T>
{
Expand Down Expand Up @@ -1837,6 +1851,14 @@ class StaticQueueBaseOptimised<T*> : public CastWrapperQueueBase<T*, typename em
} // namespace details


template <typename StorType, std::size_t TSize>
class StaticQueueArray
{
protected:
typedef std::array<StorType, TSize> ArrayType;
ArrayType array_;
};

/// @addtogroup container
/// @{

Expand All @@ -1852,8 +1874,9 @@ class StaticQueueBaseOptimised<T*> : public CastWrapperQueueBase<T*, typename em
/// elements.
/// @headerfile embxx/container/StaticQueue.h
template <typename T, std::size_t TSize>
class StaticQueue : public details::StaticQueueBaseOptimised<T>
class StaticQueue : protected StaticQueueArray<typename details::StaticQueueBaseOptimised<T>::StorageType, TSize>, public details::StaticQueueBaseOptimised<T>
{
typedef StaticQueueArray<typename details::StaticQueueBaseOptimised<T>::StorageType, TSize> Arr;
typedef details::StaticQueueBaseOptimised<T> Base;

typedef typename Base::StorageType StorageType;
Expand Down Expand Up @@ -1930,7 +1953,7 @@ class StaticQueue : public details::StaticQueueBaseOptimised<T>
/// @note Thread safety: Safe
/// @note Exception guarantee: No throw
StaticQueue()
: Base(&array_[0], TSize)
: Base(&Arr::array_[0], TSize)
{
}

Expand All @@ -1943,7 +1966,7 @@ class StaticQueue : public details::StaticQueueBaseOptimised<T>
/// @note Exception guarantee: No throw in case copy constructor
/// of the internal elements do not throw, Basic otherwise.
StaticQueue(const StaticQueue& queue)
: Base(&array_[0], TSize)
: Base(&Arr::array_[0], TSize)
{
Base::assignElements(queue);
}
Expand All @@ -1957,7 +1980,7 @@ class StaticQueue : public details::StaticQueueBaseOptimised<T>
/// @note Exception guarantee: No throw in case move constructor
/// of the internal elements do not throw, Basic otherwise.
StaticQueue(StaticQueue&& queue)
: Base(&array_[0], TSize)
: Base(&Arr::array_[0], TSize)
{
Base::assignElements(std::move(queue));
}
Expand All @@ -1973,7 +1996,7 @@ class StaticQueue : public details::StaticQueueBaseOptimised<T>
/// of the internal elements do not throw, Basic otherwise.
template <std::size_t TAnySize>
StaticQueue(const StaticQueue<T, TAnySize>& queue)
: Base(&array_[0], TSize)
: Base(&Arr::array_[0], TSize)
{
Base::assignElements(queue);
}
Expand All @@ -1988,7 +2011,7 @@ class StaticQueue : public details::StaticQueueBaseOptimised<T>
/// of the internal elements do not throw, Basic otherwise.
template <std::size_t TAnySize>
StaticQueue(StaticQueue<T, TAnySize>&& queue)
: Base(&array_[0], TSize)
: Base(&Arr::array_[0], TSize)
{
Base::assignElements(std::move(queue));
}
Expand Down Expand Up @@ -2676,21 +2699,7 @@ class StaticQueue : public details::StaticQueueBaseOptimised<T>
}

/// @brief Erase element.
/// @details Erases element from specified position
/// @param[in] pos Iterator to the element to be erased
/// @return Iterator pointing to new location of
/// the next element after the erased one.
/// @pre (pos != end())
/// @pre pos is in range [begin(), end())
/// @note Thread safety: Unsafe
/// @note Exception guarantee: No throw in case copy assignment operator
/// of the internal elements do not throw, Basic otherwise.
Iterator erase(Iterator pos)
{
auto iter = Base::erase(pos);
return *(static_cast<Iterator*>(&iter));
}

inline Iterator erase(Iterator pos);

/// @brief Returns iterator to the beginning.
/// @details This iterator works on the non-linearised queue. It has extra
Expand Down Expand Up @@ -2761,10 +2770,6 @@ class StaticQueue : public details::StaticQueueBaseOptimised<T>
return Base::operator!=(other);
}


private:
typedef std::array<StorageType, TSize> ArrayType;
ArrayType array_;
};

/// @brief Const iterator for the elements of StaticQueue.
Expand Down Expand Up @@ -3189,6 +3194,23 @@ class StaticQueue<T, TSize>::Iterator : public StaticQueue<T, TSize>::Base::Iter
}
};

/// @details Erases element from specified position
/// @param[in] pos Iterator to the element to be erased
/// @return Iterator pointing to new location of
/// the next element after the erased one.
/// @pre (pos != end())
/// @pre pos is in range [begin(), end())
/// @note Thread safety: Unsafe
/// @note Exception guarantee: No throw in case copy assignment operator
/// of the internal elements do not throw, Basic otherwise.
template <typename T, std::size_t TSize>
inline typename StaticQueue<T, TSize>::Iterator StaticQueue<T, TSize>::erase(
typename StaticQueue<T, TSize>::Iterator pos)
{
auto iter = Base::erase(pos);
return *(static_cast<Iterator*>(&iter));
}

/// @}

} // namespace container
Expand Down
2 changes: 1 addition & 1 deletion embxx/driver/Character.h
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ class CharacterReadSupport<TDevice, TEventLoop, THandler, TReadUntilPred, 1U> :

if (size == 0) {
auto code = embxx::error::ErrorCode::Success;
if (info_.readUntilPred_) {
if (static_cast<bool>(info_.readUntilPred_)) {
code = embxx::error::ErrorCode::BufferOverflow;
}
invokeHandler(Base::el_, info_, code, false);
Expand Down
2 changes: 1 addition & 1 deletion embxx/io/WriteQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ template <typename TDriver,
void WriteQueue<TDriver, TSize, THandler>::cancelAllWrites()
{
if (queue_.isEmpty()) {
return false;
return;
}

return driver_.cancelWrite();
Expand Down
11 changes: 7 additions & 4 deletions embxx/io/access.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,10 @@ typename std::decay<T>::type signExtCommon(T value, std::size_t size)
return value;
}

template <typename T, std::size_t TSize, typename TByteType>
// http://lists.llvm.org/pipermail/cfe-dev/2013-November/033677.html
template<size_t N> struct Size { static constexpr std::size_t value = N; };

template <typename T, typename TSize, typename TByteType>
class SignExt
{
public:
Expand All @@ -250,12 +253,12 @@ class SignExt

auto castedValue = static_cast<UnsignedValueType>(value);
return static_cast<ValueType>(
signExtCommon<UnsignedByteType>(castedValue, TSize));
signExtCommon<UnsignedByteType>(castedValue, TSize::value));
}
};

template <typename T, typename TByteType>
class SignExt<T, sizeof(typename std::decay<T>::type), TByteType>
class SignExt<T, Size<sizeof(typename std::decay<T>::type)>, TByteType>
{
public:
static typename std::decay<T>::type value(T value)
Expand Down Expand Up @@ -651,7 +654,7 @@ struct Reader
THelper<TEndian, IsRandomAccess>::template read<OptimisedValueType>(TSize, iter));

if (std::is_signed<ValueType>::value) {
retval = details::SignExt<decltype(retval), TSize, ByteType>::value(retval);
retval = details::SignExt<decltype(retval), Size<TSize>, ByteType>::value(retval);
}
return static_cast<T>(retval);
}
Expand Down
6 changes: 6 additions & 0 deletions embxx/io/std_streambuf_access.h
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,13 @@ T getBig(std::size_t size, std::streambuf& buf)
std::size_t remainingSize = size;
while (remainingSize > 0) {
auto byte = buf.sbumpc();

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wshift-count-overflow"
static_assert(static_cast<uint8_t>(uint8_t(std::numeric_limits<uint8_t>::max()) << 8) == 0, "shifting uint8_t by 8 should yield 0 (are you getting using an 8 bit processor?)");
value <<= 8;
#pragma clang diagnostic pop

value |= static_cast<std::uint8_t>(byte);
--remainingSize;
}
Expand Down
2 changes: 1 addition & 1 deletion embxx/util/Allocators.h
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ class SpecificInPlaceAllocator
static_assert(IsInTuple<TObj, TTuple>::Value,
"TObj must be included in TTuple");

return allocator_.alloc<TObj>(std::forward<TArgs>(args)...);
return allocator_.template alloc<TObj>(std::forward<TArgs>(args)...);
}

private:
Expand Down
9 changes: 5 additions & 4 deletions embxx/util/EventLoop.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,9 @@ class EventLoop
virtual std::size_t getSize() const;
virtual void exec();

static const std::size_t Size =
((sizeof(TaskBound<typename std::decay<TTask>::type>) - 1) / sizeof(Task)) + 1;
static constexpr std::size_t Size() {
return ((sizeof(TaskBound<typename std::decay<TTask>::type>) - 1) / sizeof(Task)) + 1;
}

private:
TTask task_;
Expand Down Expand Up @@ -416,7 +417,7 @@ template <std::size_t TSize,
template <typename TTask>
std::size_t EventLoop<TSize, TLock, TCond>::TaskBound<TTask>::getSize() const
{
return Size;
return Size();
}

template <std::size_t TSize,
Expand All @@ -440,7 +441,7 @@ bool EventLoop<TSize, TLock, TCond>::postNoLock(TTask&& task)
static_assert(std::alignment_of<Task>::value == std::alignment_of<TaskBoundType>::value,
"Alignment of TaskBound must be same as alignment of Task");

static const std::size_t requiredQueueSize = TaskBoundType::Size;
static const std::size_t requiredQueueSize = TaskBoundType::Size();

bool wasEmpty = queue_.isEmpty();

Expand Down