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

iox-#1196 Fix left-over clang-tidy warnings in cxx::vector and remove space in suppressions #1525

Merged
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
4 changes: 2 additions & 2 deletions iceoryx_hoofs/include/iceoryx_hoofs/cxx/variant.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ class variant
/// @param[in] rhs source object for the underlying move assignment
/// @return reference to the variant itself
template <typename T>
// Correct return type is used through enable_if
// NOLINTNEXTLINE (cppcoreguidelines-c-copy-assignment-signature)
// NOLINTJUSTIFICATION Correct return type is used through enable_if
// NOLINTNEXTLINE(cppcoreguidelines-c-copy-assignment-signature)
typename std::enable_if<!std::is_same<T, variant<Types...>&>::value, variant<Types...>>::type&
operator=(T&& rhs) noexcept;

Expand Down
4 changes: 2 additions & 2 deletions iceoryx_hoofs/include/iceoryx_hoofs/cxx/vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,10 @@ class vector
const T& at_unchecked(const uint64_t index) const noexcept;

/// @todo #1196 Replace with UninitializedArray
// NOLINTBEGIN(cppcoreguidelines-avoid-c-arrays)
// NOLINTBEGIN(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays)
using element_t = uint8_t[sizeof(T)];
alignas(T) element_t m_data[Capacity];
// NOLINTEND(cppcoreguidelines-avoid-c-arrays)
// NOLINTEND(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays)
uint64_t m_size{0U};
};
} // namespace cxx
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ template <typename CallableType, typename>
inline function_ref<ReturnType(ArgTypes...)>::function_ref(CallableType&& callable) noexcept
// AXIVION Next Construct AutosarC++19_03-A5.2.4, AutosarC++19_03-A5.2.3, CertC++-EXP55 : Type-safety ensured by
// casting back on call
// NOLINTNEXTLINE (cppcoreguidelines-pro-type-reinterpret-cast, cppcoreguidelines-pro-type-const-cast)
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast, cppcoreguidelines-pro-type-const-cast)
: m_pointerToCallable(const_cast<void*>(reinterpret_cast<const void*>(std::addressof(callable))))
// AXIVION Next Line AutosarC++19_03-A15.4.4 : Lambda not 'noexcept' as callable might throw
, m_functionPointer([](void* target, ArgTypes... args) -> ReturnType {
Expand All @@ -54,15 +54,15 @@ inline function_ref<ReturnType(ArgTypes...)>::function_ref(ReturnType (&function
// the cast is required to work on POSIX systems
// AXIVION Next Construct AutosarC++19_03-A5.2.4, AutosarC++19_03-A5.2.4-M5.2.6 : Type-safety ensured by casting
// back function pointer on call
// NOLINTNEXTLINE (cppcoreguidelines-pro-type-reinterpret-cast)
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
: m_pointerToCallable(reinterpret_cast<void*>(function))
,
// the lambda does not capture and is thus convertible to a function pointer
// (required by the C++ standard)
m_functionPointer([](void* target, ArgTypes... args) -> ReturnType {
using PointerType = ReturnType (*)(ArgTypes...);
// AXIVION Next Construct AutosarC++19_03-A5.2.4 : The class design ensures a cast to the actual type of target
// NOLINTNEXTLINE (cppcoreguidelines-pro-type-reinterpret-cast)
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast,hicpp-use-auto)
PointerType f = reinterpret_cast<PointerType>(target);
FerdinandSpitzschnueffler marked this conversation as resolved.
Show resolved Hide resolved
// AXIVION Next Line AutosarC++19_03-A5.3.2 : Check for 'nullptr' is performed on call
return f(args...);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ PoorMansHeap<Interface, TypeSize, TypeAlignment>::~PoorMansHeap() noexcept
deleteInstance();
}

// NOLINTNEXTLINE (cppcoreguidelines-pro-type-member-init,hicpp-member-init) justification in header
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init,hicpp-member-init) justification in header
template <typename Interface, uint64_t TypeSize, uint64_t TypeAlignment>
template <typename Type, typename... CTorArgs>
// NOLINTNEXTLINE(hicpp-named-parameter, readability-named-parameter) justification in header
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ template <typename T>
const T* unique_ptr<T>::operator->() const noexcept
{
// Avoid code duplication
// NOLINTNEXTLINE (cppcoreguidelines-pro-type-const-cast)
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast)
return const_cast<const T*>(get());
}

Expand All @@ -97,7 +97,7 @@ template <typename T>
const T* unique_ptr<T>::get() const noexcept
{
// AXIVION Next Construct AutosarC++19_03-A5.2.3 : Avoid code duplication
// NOLINTNEXTLINE (cppcoreguidelines-pro-type-const-cast)
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast)
return const_cast<unique_ptr<T>*>(this)->get();
}

Expand Down
20 changes: 10 additions & 10 deletions iceoryx_hoofs/include/iceoryx_hoofs/internal/cxx/variant.inl
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,17 @@ inline constexpr variant<Types...>::variant(const variant& rhs) noexcept

template <typename... Types>
template <uint64_t N, typename... CTorArguments>
// First param is helper struct only
// NOLINTNEXTLINE (hicpp-named-parameter)
// NOLINTJUSTIFICATION First param is helper struct only
// NOLINTNEXTLINE(hicpp-named-parameter)
inline constexpr variant<Types...>::variant(const in_place_index<N>&, CTorArguments&&... args) noexcept
{
emplace_at_index<N>(std::forward<CTorArguments>(args)...);
}

template <typename... Types>
template <typename T, typename... CTorArguments>
// First param is helper struct only
// NOLINTNEXTLINE (hicpp-named-parameter)
// NOLINTJUSTIFICATION First param is helper struct only
// NOLINTNEXTLINE(hicpp-named-parameter)
inline constexpr variant<Types...>::variant(const in_place_type<T>&, CTorArguments&&... args) noexcept
{
emplace<T>(std::forward<CTorArguments>(args)...);
Expand Down Expand Up @@ -138,8 +138,8 @@ inline void variant<Types...>::call_element_destructor() noexcept
}
}

// Correct return type is used through enable_if
// NOLINTNEXTLINE (cppcoreguidelines-c-copy-assignment-signature)
// NOLINTJUSTIFICATION Correct return type is used through enable_if
// NOLINTNEXTLINE(cppcoreguidelines-c-copy-assignment-signature)
template <typename... Types>
template <typename T>
inline typename std::enable_if<!std::is_same<T, variant<Types...>&>::value, variant<Types...>>::type&
Expand Down Expand Up @@ -224,7 +224,7 @@ variant<Types...>::get_at_index() 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)
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast)
return const_cast<const T*>(const_cast<variant*>(this)->template get_at_index<TypeIndex>());
}

Expand All @@ -237,7 +237,7 @@ inline const T* variant<Types...>::get() const noexcept
return nullptr;
}
// AXIVION Next Construct AutosarC++19_03-A5.2.3 : avoid code duplication
// NOLINTNEXTLINE (cppcoreguidelines-pro-type-const-cast)
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast)
return static_cast<const T*>(static_cast<const void*>(m_storage));
}

Expand All @@ -246,7 +246,7 @@ template <typename T>
inline T* variant<Types...>::get() noexcept
{
// AXIVION Next Construct AutosarC++19_03-A5.2.3 : avoid code duplication
// NOLINTNEXTLINE (cppcoreguidelines-pro-type-const-cast)
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast)
return const_cast<T*>(const_cast<const variant*>(this)->get<T>());
}

Expand All @@ -255,7 +255,7 @@ template <typename T>
inline T* variant<Types...>::get_if(T* defaultValue) noexcept
{
// AXIVION Next Construct AutosarC++19_03-A5.2.3 : avoid code duplication
// NOLINTNEXTLINE (cppcoreguidelines-pro-type-const-cast)
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast)
return const_cast<T*>(const_cast<const variant*>(this)->get_if<T>(const_cast<const T*>(defaultValue)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ struct call_at_index
if (N == index)
{
// AXIVION Next Construct AutosarC++19_03-A5.2.4 : Type safety ensured through template parameter
// NOLINTNEXTLINE (cppcoreguidelines-pro-type-reinterpret-cast)
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
reinterpret_cast<T*>(ptr)->~T();
}
else
Expand All @@ -113,7 +113,7 @@ struct call_at_index
if (N == index)
{
// AXIVION Next Construct AutosarC++19_03-A5.2.4 : Type safety ensured through template parameter
// NOLINTNEXTLINE (cppcoreguidelines-pro-type-reinterpret-cast)
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
*reinterpret_cast<T*>(destination) = std::move(*reinterpret_cast<T*>(source));
}
else
Expand All @@ -127,7 +127,7 @@ struct call_at_index
if (N == index)
{
// AXIVION Next Construct AutosarC++19_03-A5.2.4 : Type safety ensured through template parameter
// NOLINTNEXTLINE (cppcoreguidelines-pro-type-reinterpret-cast)
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
new (destination) T(std::move(*reinterpret_cast<T*>(source)));
}
else
Expand All @@ -141,7 +141,7 @@ struct call_at_index
if (N == index)
{
// AXIVION Next Construct AutosarC++19_03-A5.2.4 : Type safety ensured through template parameter
// NOLINTNEXTLINE (cppcoreguidelines-pro-type-reinterpret-cast)
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
*reinterpret_cast<T*>(destination) = *reinterpret_cast<const T*>(source);
}
else
Expand All @@ -155,7 +155,7 @@ struct call_at_index
if (N == index)
{
// AXIVION Next Construct AutosarC++19_03-A5.2.4 : Type safety ensured through template parameter
// NOLINTNEXTLINE (cppcoreguidelines-pro-type-reinterpret-cast)
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
new (destination) T(*reinterpret_cast<const T*>(source));
}
else
Expand All @@ -168,14 +168,14 @@ struct call_at_index
template <uint64_t N, typename T>
struct call_at_index<N, T>
{
// d'tor changes the data to which source is pointing to
// NOLINTNEXTLINE (readability-non-const-parameter)
// NOLINTJUSTIFICATION d'tor changes the data to which source is pointing to
// NOLINTNEXTLINE(readability-non-const-parameter)
static void destructor(const uint64_t index, byte_t* ptr) noexcept
{
if (N == index)
{
// AXIVION Next Construct AutosarC++19_03-A5.2.4 : Type safety ensured through template parameter
// NOLINTNEXTLINE (cppcoreguidelines-pro-type-reinterpret-cast)
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
reinterpret_cast<T*>(ptr)->~T();
}
else
Expand All @@ -184,14 +184,14 @@ struct call_at_index<N, T>
}
}

// move c'tor changes the data to which source is pointing to
// NOLINTNEXTLINE (readability-non-const-parameter)
// NOLINTJUSTIFICATION move c'tor changes the data to which source is pointing to
// NOLINTNEXTLINE(readability-non-const-parameter)
static void move(const uint64_t index, byte_t* source, byte_t* destination) noexcept
{
if (N == index)
{
// AXIVION Next Construct AutosarC++19_03-A5.2.4 : Type safety ensured through template parameter
// NOLINTNEXTLINE (cppcoreguidelines-pro-type-reinterpret-cast)
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
*reinterpret_cast<T*>(destination) = std::move(*reinterpret_cast<T*>(source));
}
else
Expand All @@ -200,14 +200,14 @@ struct call_at_index<N, T>
}
}

// Both 'source' and 'destination' will be changed and can't be const
// NOLINTNEXTLINE (readability-non-const-parameter)
// NOLINTJUSTIFICATION Both 'source' and 'destination' will be changed and can't be const
// NOLINTNEXTLINE(readability-non-const-parameter)
static void moveConstructor(const uint64_t index, byte_t* source, byte_t* destination) noexcept
{
if (N == index)
{
// AXIVION Next Construct AutosarC++19_03-A5.2.4 : Type safety ensured through template parameter
// NOLINTNEXTLINE (cppcoreguidelines-pro-type-reinterpret-cast)
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
new (destination) T(std::move(*reinterpret_cast<T*>(source)));
}
else
Expand All @@ -221,7 +221,7 @@ struct call_at_index<N, T>
if (N == index)
{
// AXIVION Next Construct AutosarC++19_03-A5.2.4 : Type safety ensured through template parameter
// NOLINTNEXTLINE (cppcoreguidelines-pro-type-reinterpret-cast)
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
*reinterpret_cast<T*>(destination) = *reinterpret_cast<const T*>(source);
}
else
Expand All @@ -230,14 +230,14 @@ struct call_at_index<N, T>
}
}

// 'operator new()' needs non-const 'destination'
// NOLINTNEXTLINE (readability-non-const-parameter)
// NOLINTJUSTIFICATION 'operator new()' needs non-const 'destination'
mossmaurice marked this conversation as resolved.
Show resolved Hide resolved
// NOLINTNEXTLINE(readability-non-const-parameter)
static void copyConstructor(const uint64_t index, const byte_t* source, byte_t* destination) noexcept
{
if (N == index)
{
// AXIVION Next Construct AutosarC++19_03-A5.2.4 : Type safety ensured through template parameter
// NOLINTNEXTLINE (cppcoreguidelines-pro-type-reinterpret-cast)
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
new (destination) T(*reinterpret_cast<const T*>(source));
}
else
Expand Down
29 changes: 19 additions & 10 deletions iceoryx_hoofs/include/iceoryx_hoofs/internal/cxx/vector.inl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ namespace iox
{
namespace cxx
{
// NOLINTJUSTIFICATION See header and todo, using UninitializedArray will solve the issue
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init,hicpp-member-init)
template <typename T, uint64_t Capacity>
inline vector<T, Capacity>::vector(const uint64_t count, const T& value) noexcept
{
Expand All @@ -41,6 +43,8 @@ inline vector<T, Capacity>::vector(const uint64_t count, const T& value) noexcep
}
}

// NOLINTJUSTIFICATION Not all elements in the array shall be initialized
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init,hicpp-member-init)
template <typename T, uint64_t Capacity>
inline vector<T, Capacity>::vector(const uint64_t count) noexcept
{
Expand All @@ -58,12 +62,16 @@ inline vector<T, Capacity>::vector(const uint64_t count) noexcept
}
}

// NOLINTJUSTIFICATION Not all elements in the array shall be initialized
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init,hicpp-member-init)
template <typename T, uint64_t Capacity>
inline vector<T, Capacity>::vector(const vector& rhs) noexcept
{
*this = rhs;
}

// NOLINTJUSTIFICATION Not all elements in the array shall be initialized
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init,hicpp-member-init)
template <typename T, uint64_t Capacity>
inline vector<T, Capacity>::vector(vector&& rhs) noexcept
{
Expand Down Expand Up @@ -250,7 +258,7 @@ template <typename T, uint64_t Capacity>
inline T* vector<T, Capacity>::data() noexcept
{
// AXIVION Next Line AutosarC++19_03-A5.2.3 : const cast to avoid code duplication
// NOLINTNEXTLINE (cppcoreguidelines-pro-type-const-cast)
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast)
return const_cast<T*>(const_cast<const vector<T, Capacity>*>(this)->data());
}

Expand All @@ -264,7 +272,7 @@ template <typename T, uint64_t Capacity>
inline T& vector<T, Capacity>::at(const uint64_t index) noexcept
{
// AXIVION Next Construct AutosarC++19_03-A5.2.3 : const cast to avoid code duplication
// NOLINTNEXTLINE (cppcoreguidelines-pro-type-const-cast)
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast)
return const_cast<T&>(const_cast<const vector<T, Capacity>*>(this)->at(index));
}

Expand Down Expand Up @@ -298,7 +306,7 @@ template <typename T, uint64_t Capacity>
inline const T& vector<T, Capacity>::front() const noexcept
{
// AXIVION Next Construct AutosarC++19_03-A5.2.3 : const cast to avoid code duplication
// NOLINTNEXTLINE (cppcoreguidelines-pro-type-const-cast)
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast)
return const_cast<vector<T, Capacity>*>(this)->front();
}

Expand All @@ -313,39 +321,39 @@ template <typename T, uint64_t Capacity>
inline const T& vector<T, Capacity>::back() const noexcept
{
// AXIVION Next Construct AutosarC++19_03-A5.2.3 : const cast to avoid code duplication
// NOLINTNEXTLINE (cppcoreguidelines-pro-type-const-cast)
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast)
return const_cast<vector<T, Capacity>*>(this)->back();
}

template <typename T, uint64_t Capacity>
inline typename vector<T, Capacity>::iterator vector<T, Capacity>::begin() noexcept
{
// AXIVION Next Construct AutosarC++19_03-A5.2.3 : const cast to avoid code duplication
// NOLINTNEXTLINE (cppcoreguidelines-pro-type-const-cast)
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast)
return const_cast<iterator>(const_cast<const vector<T, Capacity>*>(this)->begin());
}

template <typename T, uint64_t Capacity>
inline typename vector<T, Capacity>::const_iterator vector<T, Capacity>::begin() const noexcept
{
// AXIVION Next Construct AutosarC++19_03-A5.2.4 : Type-safety ensured by template parameter
// NOLINTNEXTLINE (cppcoreguidelines-pro-type-reinterpret-cast)
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
return reinterpret_cast<const_iterator>(&at_unchecked(0));
}

template <typename T, uint64_t Capacity>
inline typename vector<T, Capacity>::iterator vector<T, Capacity>::end() noexcept
{
// AXIVION Next Construct AutosarC++19_03-A5.2.3 : const cast to avoid code duplication
// NOLINTNEXTLINE (cppcoreguidelines-pro-type-const-cast)
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast)
return const_cast<iterator>(const_cast<const vector<T, Capacity>*>(this)->end());
}

template <typename T, uint64_t Capacity>
inline typename vector<T, Capacity>::const_iterator vector<T, Capacity>::end() const noexcept
{
// AXIVION Next Construct AutosarC++19_03-A5.2.4 : Type-safety ensured by template parameter
// NOLINTNEXTLINE (cppcoreguidelines-pro-type-reinterpret-cast)
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
return reinterpret_cast<const_iterator>(&(at_unchecked(0)) + m_size);
}

Expand All @@ -370,15 +378,16 @@ template <typename T, uint64_t Capacity>
T& vector<T, Capacity>::at_unchecked(const uint64_t index) noexcept
{
// AXIVION Next Construct AutosarC++19_03-A5.2.3 : const cast to avoid code duplication
// NOLINTNEXTLINE (cppcoreguidelines-pro-type-const-cast)
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast)
return const_cast<T&>(const_cast<const vector<T, Capacity>*>(this)->at_unchecked(index));
}

template <typename T, uint64_t Capacity>
const T& vector<T, Capacity>::at_unchecked(const uint64_t index) const noexcept
{
// AXIVION Next Construct AutosarC++19_03-A5.2.4 : Type-safety ensured by template parameter
// NOLINTNEXTLINE (cppcoreguidelines-pro-type-reinterpret-cast)
// NOLINTJUSTIFICATION User accessible method at() performs bounds check
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think bound checks have nothing to do with a reinterpret_cast usage.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@elfenpiff You have to look more carefully above and below ;) Here, two warnings are suppressed:

  1. reinterpret_cast for Axivion with justification and clang-tidy without duplicate justification
  2. Bounds safety issue of working with raw array instead of std::span, justification only for clang-tidy

// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast,cppcoreguidelines-pro-bounds-pointer-arithmetic)
return reinterpret_cast<const T*>(m_data)[index];
}

Expand Down
Loading