-
Notifications
You must be signed in to change notification settings - Fork 403
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2089 from eclipse-iceoryx/iox-2047-fix-gcc-13-war…
…nings iox-#2047 Fix gcc 13 warnings
- Loading branch information
Showing
10 changed files
with
186 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
// Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. | ||
// Copyright (c) 2020 - 2022 by Apex.AI Inc. All rights reserved. | ||
// Copyright (c) 2023 by Mathias Kraus <[email protected]>. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
|
@@ -56,34 +57,38 @@ optional<ValueType> VariantQueue<ValueType, Capacity>::push(const ValueType& val | |
{ | ||
case VariantQueueTypes::FiFo_SingleProducerSingleConsumer: | ||
{ | ||
auto hadSpace = | ||
m_fifo.template get_at_index<static_cast<uint64_t>(VariantQueueTypes::FiFo_SingleProducerSingleConsumer)>() | ||
->push(value); | ||
// SAFETY: 'm_type' ist 'const' and does not change after construction | ||
auto* queue = m_fifo.template unsafe_get_at_index_unchecked<static_cast<uint64_t>( | ||
VariantQueueTypes::FiFo_SingleProducerSingleConsumer)>(); | ||
auto hadSpace = queue->push(value); | ||
|
||
return (hadSpace) ? nullopt : make_optional<ValueType>(value); | ||
} | ||
case VariantQueueTypes::SoFi_SingleProducerSingleConsumer: | ||
{ | ||
ValueType overriddenValue; | ||
auto hadSpace = | ||
m_fifo.template get_at_index<static_cast<uint64_t>(VariantQueueTypes::SoFi_SingleProducerSingleConsumer)>() | ||
->push(value, overriddenValue); | ||
// SAFETY: 'm_type' ist 'const' and does not change after construction | ||
auto* queue = m_fifo.template unsafe_get_at_index_unchecked<static_cast<uint64_t>( | ||
VariantQueueTypes::SoFi_SingleProducerSingleConsumer)>(); | ||
auto hadSpace = queue->push(value, overriddenValue); | ||
|
||
return (hadSpace) ? nullopt : make_optional<ValueType>(overriddenValue); | ||
} | ||
case VariantQueueTypes::FiFo_MultiProducerSingleConsumer: | ||
{ | ||
auto hadSpace = | ||
m_fifo.template get_at_index<static_cast<uint64_t>(VariantQueueTypes::FiFo_MultiProducerSingleConsumer)>() | ||
->tryPush(value); | ||
// SAFETY: 'm_type' ist 'const' and does not change after construction | ||
auto* queue = m_fifo.template unsafe_get_at_index_unchecked<static_cast<uint64_t>( | ||
VariantQueueTypes::FiFo_MultiProducerSingleConsumer)>(); | ||
auto hadSpace = queue->tryPush(value); | ||
|
||
return (hadSpace) ? nullopt : make_optional<ValueType>(value); | ||
} | ||
case VariantQueueTypes::SoFi_MultiProducerSingleConsumer: | ||
{ | ||
return m_fifo | ||
.template get_at_index<static_cast<uint64_t>(VariantQueueTypes::FiFo_MultiProducerSingleConsumer)>() | ||
->push(value); | ||
// SAFETY: 'm_type' ist 'const' and does not change after construction | ||
auto* queue = m_fifo.template unsafe_get_at_index_unchecked<static_cast<uint64_t>( | ||
VariantQueueTypes::FiFo_MultiProducerSingleConsumer)>(); | ||
return queue->push(value); | ||
} | ||
} | ||
|
||
|
@@ -97,25 +102,28 @@ inline optional<ValueType> VariantQueue<ValueType, Capacity>::pop() noexcept | |
{ | ||
case VariantQueueTypes::FiFo_SingleProducerSingleConsumer: | ||
{ | ||
return m_fifo | ||
.template get_at_index<static_cast<uint64_t>(VariantQueueTypes::FiFo_SingleProducerSingleConsumer)>() | ||
->pop(); | ||
// SAFETY: 'm_type' ist 'const' and does not change after construction | ||
auto* queue = m_fifo.template unsafe_get_at_index_unchecked<static_cast<uint64_t>( | ||
VariantQueueTypes::FiFo_SingleProducerSingleConsumer)>(); | ||
return queue->pop(); | ||
} | ||
case VariantQueueTypes::SoFi_SingleProducerSingleConsumer: | ||
{ | ||
ValueType returnType; | ||
auto hasReturnType = | ||
m_fifo.template get_at_index<static_cast<uint64_t>(VariantQueueTypes::SoFi_SingleProducerSingleConsumer)>() | ||
->pop(returnType); | ||
// SAFETY: 'm_type' ist 'const' and does not change after construction | ||
auto* queue = m_fifo.template unsafe_get_at_index_unchecked<static_cast<uint64_t>( | ||
VariantQueueTypes::SoFi_SingleProducerSingleConsumer)>(); | ||
auto hasReturnType = queue->pop(returnType); | ||
|
||
return (hasReturnType) ? make_optional<ValueType>(returnType) : nullopt; | ||
} | ||
case VariantQueueTypes::FiFo_MultiProducerSingleConsumer: | ||
case VariantQueueTypes::SoFi_MultiProducerSingleConsumer: | ||
{ | ||
return m_fifo | ||
.template get_at_index<static_cast<uint64_t>(VariantQueueTypes::FiFo_MultiProducerSingleConsumer)>() | ||
->pop(); | ||
// SAFETY: 'm_type' ist 'const' and does not change after construction | ||
auto* queue = m_fifo.template unsafe_get_at_index_unchecked<static_cast<uint64_t>( | ||
VariantQueueTypes::FiFo_MultiProducerSingleConsumer)>(); | ||
return queue->pop(); | ||
} | ||
} | ||
|
||
|
@@ -129,22 +137,25 @@ inline bool VariantQueue<ValueType, Capacity>::empty() const noexcept | |
{ | ||
case VariantQueueTypes::FiFo_SingleProducerSingleConsumer: | ||
{ | ||
return m_fifo | ||
.template get_at_index<static_cast<uint64_t>(VariantQueueTypes::FiFo_SingleProducerSingleConsumer)>() | ||
->empty(); | ||
// SAFETY: 'm_type' ist 'const' and does not change after construction | ||
auto* queue = m_fifo.template unsafe_get_at_index_unchecked<static_cast<uint64_t>( | ||
VariantQueueTypes::FiFo_SingleProducerSingleConsumer)>(); | ||
return queue->empty(); | ||
} | ||
case VariantQueueTypes::SoFi_SingleProducerSingleConsumer: | ||
{ | ||
return m_fifo | ||
.template get_at_index<static_cast<uint64_t>(VariantQueueTypes::SoFi_SingleProducerSingleConsumer)>() | ||
->empty(); | ||
// SAFETY: 'm_type' ist 'const' and does not change after construction | ||
auto* queue = m_fifo.template unsafe_get_at_index_unchecked<static_cast<uint64_t>( | ||
VariantQueueTypes::SoFi_SingleProducerSingleConsumer)>(); | ||
return queue->empty(); | ||
} | ||
case VariantQueueTypes::FiFo_MultiProducerSingleConsumer: | ||
case VariantQueueTypes::SoFi_MultiProducerSingleConsumer: | ||
{ | ||
return m_fifo | ||
.template get_at_index<static_cast<uint64_t>(VariantQueueTypes::FiFo_MultiProducerSingleConsumer)>() | ||
->empty(); | ||
// SAFETY: 'm_type' ist 'const' and does not change after construction | ||
auto* queue = m_fifo.template unsafe_get_at_index_unchecked<static_cast<uint64_t>( | ||
VariantQueueTypes::FiFo_MultiProducerSingleConsumer)>(); | ||
return queue->empty(); | ||
} | ||
} | ||
|
||
|
@@ -158,25 +169,25 @@ inline uint64_t VariantQueue<ValueType, Capacity>::size() noexcept | |
{ | ||
case VariantQueueTypes::FiFo_SingleProducerSingleConsumer: | ||
{ | ||
return m_fifo | ||
.template get_at_index<static_cast<uint64_t>(VariantQueueTypes::FiFo_SingleProducerSingleConsumer)>() | ||
->size(); | ||
break; | ||
// SAFETY: 'm_type' ist 'const' and does not change after construction | ||
auto* queue = m_fifo.template unsafe_get_at_index_unchecked<static_cast<uint64_t>( | ||
VariantQueueTypes::FiFo_SingleProducerSingleConsumer)>(); | ||
return queue->size(); | ||
} | ||
case VariantQueueTypes::SoFi_SingleProducerSingleConsumer: | ||
{ | ||
return m_fifo | ||
.template get_at_index<static_cast<uint64_t>(VariantQueueTypes::SoFi_SingleProducerSingleConsumer)>() | ||
->size(); | ||
break; | ||
// SAFETY: 'm_type' ist 'const' and does not change after construction | ||
auto* queue = m_fifo.template unsafe_get_at_index_unchecked<static_cast<uint64_t>( | ||
VariantQueueTypes::SoFi_SingleProducerSingleConsumer)>(); | ||
return queue->size(); | ||
} | ||
case VariantQueueTypes::FiFo_MultiProducerSingleConsumer: | ||
case VariantQueueTypes::SoFi_MultiProducerSingleConsumer: | ||
{ | ||
return m_fifo | ||
.template get_at_index<static_cast<uint64_t>(VariantQueueTypes::FiFo_MultiProducerSingleConsumer)>() | ||
->size(); | ||
break; | ||
// SAFETY: 'm_type' ist 'const' and does not change after construction | ||
auto* queue = m_fifo.template unsafe_get_at_index_unchecked<static_cast<uint64_t>( | ||
VariantQueueTypes::FiFo_MultiProducerSingleConsumer)>(); | ||
return queue->size(); | ||
} | ||
} | ||
|
||
|
@@ -197,17 +208,20 @@ inline bool VariantQueue<ValueType, Capacity>::setCapacity(const uint64_t newCap | |
} | ||
case VariantQueueTypes::SoFi_SingleProducerSingleConsumer: | ||
{ | ||
m_fifo.template get_at_index<static_cast<uint64_t>(VariantQueueTypes::SoFi_SingleProducerSingleConsumer)>() | ||
->setCapacity(newCapacity); | ||
// SAFETY: 'm_type' ist 'const' and does not change after construction | ||
auto* queue = m_fifo.template unsafe_get_at_index_unchecked<static_cast<uint64_t>( | ||
VariantQueueTypes::SoFi_SingleProducerSingleConsumer)>(); | ||
queue->setCapacity(newCapacity); | ||
return true; | ||
} | ||
case VariantQueueTypes::FiFo_MultiProducerSingleConsumer: | ||
case VariantQueueTypes::SoFi_MultiProducerSingleConsumer: | ||
{ | ||
// SAFETY: 'm_type' ist 'const' and does not change after construction | ||
auto* queue = m_fifo.template unsafe_get_at_index_unchecked<static_cast<uint64_t>( | ||
VariantQueueTypes::FiFo_MultiProducerSingleConsumer)>(); | ||
// we may discard elements in the queue if the size is reduced and the fifo contains too many elements | ||
return m_fifo | ||
.template get_at_index<static_cast<uint64_t>(VariantQueueTypes::FiFo_MultiProducerSingleConsumer)>() | ||
->setCapacity(newCapacity); | ||
return queue->setCapacity(newCapacity); | ||
} | ||
} | ||
return false; | ||
|
@@ -220,25 +234,25 @@ inline uint64_t VariantQueue<ValueType, Capacity>::capacity() const noexcept | |
{ | ||
case VariantQueueTypes::FiFo_SingleProducerSingleConsumer: | ||
{ | ||
return m_fifo | ||
.template get_at_index<static_cast<uint64_t>(VariantQueueTypes::FiFo_SingleProducerSingleConsumer)>() | ||
->capacity(); | ||
break; | ||
// SAFETY: 'm_type' ist 'const' and does not change after construction | ||
auto* queue = m_fifo.template unsafe_get_at_index_unchecked<static_cast<uint64_t>( | ||
VariantQueueTypes::FiFo_SingleProducerSingleConsumer)>(); | ||
return queue->capacity(); | ||
} | ||
case VariantQueueTypes::SoFi_SingleProducerSingleConsumer: | ||
{ | ||
return m_fifo | ||
.template get_at_index<static_cast<uint64_t>(VariantQueueTypes::SoFi_SingleProducerSingleConsumer)>() | ||
->capacity(); | ||
break; | ||
// SAFETY: 'm_type' ist 'const' and does not change after construction | ||
auto* queue = m_fifo.template unsafe_get_at_index_unchecked<static_cast<uint64_t>( | ||
VariantQueueTypes::SoFi_SingleProducerSingleConsumer)>(); | ||
return queue->capacity(); | ||
} | ||
case VariantQueueTypes::FiFo_MultiProducerSingleConsumer: | ||
case VariantQueueTypes::SoFi_MultiProducerSingleConsumer: | ||
{ | ||
return m_fifo | ||
.template get_at_index<static_cast<uint64_t>(VariantQueueTypes::FiFo_MultiProducerSingleConsumer)>() | ||
->capacity(); | ||
break; | ||
// SAFETY: 'm_type' ist 'const' and does not change after construction | ||
auto* queue = m_fifo.template unsafe_get_at_index_unchecked<static_cast<uint64_t>( | ||
VariantQueueTypes::FiFo_MultiProducerSingleConsumer)>(); | ||
return queue->capacity(); | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
// Copyright (c) 2019 by Robert Bosch GmbH. All rights reserved. | ||
// Copyright (c) 2021 - 2023 by Apex.AI Inc. All rights reserved. | ||
// Copyright (c) 2023 by Mathias Kraus <[email protected]>. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
|
@@ -164,17 +165,35 @@ inline string<Capacity>& string<Capacity>::operator=(const char (&rhs)[N]) noexc | |
return *this; | ||
} | ||
|
||
std::memcpy(m_rawstring, rhs, N); | ||
const auto sourceRawStringSize = static_cast<uint64_t>(strnlen(&rhs[0], N)); | ||
if (sourceRawStringSize <= Capacity) | ||
{ | ||
m_rawstringSize = sourceRawStringSize; | ||
} | ||
else | ||
{ | ||
m_rawstringSize = Capacity; | ||
|
||
IOX_LOG( | ||
WARN, | ||
"iox::string: Assignment of array which is not zero-terminated! Last value of array overwritten with 0!"); | ||
} | ||
|
||
// AXIVION DISABLE STYLE AutosarC++19_03-A16.0.1: pre-processor is required for setting gcc diagnostics, since gcc 8 incorrectly warns here about out of bounds array access | ||
// AXIVION DISABLE STYLE AutosarC++19_03-A16.7.1: see rule 'A16.0.1' above | ||
#if (defined(__GNUC__) && (__GNUC__ == 8)) && (__GNUC_MINOR__ >= 3) | ||
#pragma GCC diagnostic push | ||
#pragma GCC diagnostic ignored "-Warray-bounds" | ||
#endif | ||
std::memcpy(m_rawstring, rhs, m_rawstringSize); | ||
#if (defined(__GNUC__) && (__GNUC__ == 8)) && (__GNUC_MINOR__ >= 3) | ||
#pragma GCC diagnostic pop | ||
#endif | ||
// AXIVION ENABLE STYLE AutosarC++19_03-A16.7.1 | ||
// AXIVION ENABLE STYLE AutosarC++19_03-A16.0.1 | ||
|
||
m_rawstringSize = std::min(Capacity, static_cast<uint64_t>(strnlen(&rhs[0], N))); | ||
m_rawstring[m_rawstringSize] = '\0'; | ||
|
||
if (rhs[m_rawstringSize] != '\0') | ||
{ | ||
IOX_LOG(WARN, | ||
"iox::string: Assignment of array which is not zero-terminated! Last value of array " | ||
"overwritten with 0!"); | ||
} | ||
return *this; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
// Copyright (c) 2019 by Robert Bosch GmbH. All rights reserved. | ||
// Copyright (c) 2021 - 2022 by Apex.AI Inc. All rights reserved. | ||
// Copyright (c) 2021 by Perforce All rights reserved. | ||
// Copyright (c) 2023 by Mathias Kraus <[email protected]>. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
|
@@ -204,6 +205,14 @@ inline typename internal::get_type_at_index<0, TypeIndex, Types...>::type* varia | |
return nullptr; | ||
} | ||
|
||
return unsafe_get_at_index_unchecked<TypeIndex>(); | ||
} | ||
|
||
template <typename... Types> | ||
template <uint64_t TypeIndex> | ||
inline typename internal::get_type_at_index<0, TypeIndex, Types...>::type* | ||
variant<Types...>::unsafe_get_at_index_unchecked() noexcept | ||
{ | ||
using T = typename internal::get_type_at_index<0, TypeIndex, Types...>::type; | ||
|
||
// AXIVION Next Construct AutosarC++19_03-M5.2.8 : conversion to typed pointer is intentional, it is correctly aligned and points to sufficient memory for a T by design | ||
|
@@ -221,6 +230,17 @@ variant<Types...>::get_at_index() const noexcept | |
return const_cast<const T*>(const_cast<variant*>(this)->template get_at_index<TypeIndex>()); | ||
} | ||
|
||
template <typename... Types> | ||
template <uint64_t TypeIndex> | ||
inline const typename internal::get_type_at_index<0, TypeIndex, Types...>::type* | ||
variant<Types...>::unsafe_get_at_index_unchecked() const noexcept | ||
{ | ||
using T = typename internal::get_type_at_index<0, TypeIndex, Types...>::type; | ||
// AXIVION Next Construct AutosarC++19_03-A5.2.3 : avoid code duplication | ||
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast) | ||
return const_cast<const T*>(const_cast<variant*>(this)->template unsafe_get_at_index_unchecked<TypeIndex>()); | ||
} | ||
|
||
template <typename... Types> | ||
template <typename T> | ||
inline const T* variant<Types...>::get() const noexcept | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
// Copyright (c) 2019 by Robert Bosch GmbH. All rights reserved. | ||
// Copyright (c) 2021 - 2022 by Apex.AI Inc. All rights reserved. | ||
// Copyright (c) 2023 by Mathias Kraus <[email protected]>. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
|
@@ -212,6 +213,15 @@ class variant final | |
template <uint64_t TypeIndex> | ||
typename internal::get_type_at_index<0, TypeIndex, Types...>::type* get_at_index() noexcept; | ||
|
||
/// @brief returns a pointer to the type stored at index TypeIndex. (not stl compliant) | ||
/// @tparam[in] TypeIndex index of the stored type | ||
/// @return a pointer to the type at index | ||
/// @attention this function is unsafe and does not check if the type at the index is the current active one; only | ||
/// use this function when it is ensured that the type at index is indeed the current active one; it is undefined | ||
/// behavior to call this on an index which is not the active type | ||
template <uint64_t TypeIndex> | ||
typename internal::get_type_at_index<0, TypeIndex, Types...>::type* unsafe_get_at_index_unchecked() noexcept; | ||
|
||
/// @brief returns a pointer to the type stored at index TypeIndex. (not stl compliant) | ||
/// @tparam[in] TypeIndex index of the stored type | ||
/// @return if the variant does contain the type at index TypeIndex it returns a valid | ||
|
@@ -224,6 +234,16 @@ class variant final | |
template <uint64_t TypeIndex> | ||
const typename internal::get_type_at_index<0, TypeIndex, Types...>::type* get_at_index() const noexcept; | ||
|
||
/// @brief returns a pointer to the type stored at index TypeIndex. (not stl compliant) | ||
/// @tparam[in] TypeIndex index of the stored type | ||
/// @return a const pointer to the type at index | ||
/// @attention this function is unsafe and does not check if the type at the index is the current active one; only | ||
/// use this function when it is ensured that the type at index is indeed the current active one; it is undefined | ||
/// behavior to call this on an index which is not the active type | ||
template <uint64_t TypeIndex> | ||
const typename internal::get_type_at_index<0, TypeIndex, Types...>::type* | ||
unsafe_get_at_index_unchecked() const noexcept; | ||
|
||
/// @brief returns a pointer to the type T stored in the variant. (not stl compliant) | ||
/// @tparam[in] T type of the returned pointer | ||
/// @return if the variant does contain the type T it returns a valid pointer otherwise | ||
|
Oops, something went wrong.