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-#2274 Fix clang-tidy-18 warnings #2275

Merged
merged 3 commits into from
Apr 24, 2024
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
16 changes: 14 additions & 2 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ concurrency-*,
performance-*,
hicpp-*,

-cppcoreguidelines-avoid-do-while
-cppcoreguidelines-avoid-do-while,
-cppcoreguidelines-non-private-member-variables-in-classes,

-hicpp-named-parameter,
Expand All @@ -30,13 +30,16 @@ hicpp-*,
-readability-identifier-length,
-readability-redundant-access-specifiers,
-readability-redundant-declaration,
-readability-redundant-inline-specifier,
-readability-static-accessed-through-instance,

-readability-identifier-naming,
-readability-use-anyofallof,
-readability-named-parameter,

-cert-dcl21-cpp
-performance-avoid-endl,

-cert-dcl21-cpp,

'

Expand Down Expand Up @@ -98,6 +101,9 @@ hicpp-*,
# // in cpp file
# void bar(Foo& foo) {...}
#
# * rule: readability-redundant-inline-specifier
# justicfication: there are many false positives
#
# * rule: readability-use-anyofallof
# justification: requires C++20 and std::ranges but we only use C++17
#
Expand Down Expand Up @@ -132,6 +138,12 @@ hicpp-*,
# Tag1 tag;
# foo(tag); // calls (1)
#
# * rule: performance-avoid-endl
# justification: 'iostream' is only used in a few places where the logger either cannot be used, likt the platform layer, or
# we want to print immediatelly something on the screen like the command line parser or the examples. In this
# cases we would immediatelly after the '\n' calls 'std::flush'. Therefore we keep using 'std::endl' in this
# limited places.
#
## Those warnings should be enabled
## They are disabled since they require a heavy API refactoring and when we enable it we clutter the code with // NOLINT comments
# -bugprone-easily-swappable-parameters
Expand Down
4 changes: 2 additions & 2 deletions .clang-tidy-diff-scans.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
./iceoryx_hoofs/**/*

./iceoryx_posh/include/iox/**/*
./iceoryx_posh/source/posh/**/*
./iceoryx_posh/experimental/include/iox/**/*
./iceoryx_posh/experimental/source/**/*

# IMPORTANT:
# after the first # everything is considered a comment, add new files and
Expand Down
1 change: 1 addition & 0 deletions doc/website/release-notes/iceoryx-unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@
- Split `iceoryx_hoofs` into logical modules [#1391](https://github.com/eclipse-iceoryx/iceoryx/issues/1391)
- Create a flat include structure for `iceoryx_hoofs` [#1593](https://github.com/eclipse-iceoryx/iceoryx/issues/1593)
- Handle 'strerror_r' idiosyncrasies in the platform layer [#1616](https://github.com/eclipse-iceoryx/iceoryx/issues/1616)
- Fix new clang-tidy-18 warnings [#2274](https://github.com/eclipse-iceoryx/iceoryx/issues/2274)

**Workflow:**

Expand Down
1 change: 1 addition & 0 deletions iceoryx_hoofs/buffer/include/iox/detail/stack.inl
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ inline stack<T, Capacity>& stack<T, Capacity>::copy(const stack& rhs) noexcept
}

template <typename T, uint64_t Capacity>
// NOLINTNEXTLINE(cppcoreguidelines-rvalue-reference-param-not-moved) false positive, the elements are moved
inline stack<T, Capacity>& stack<T, Capacity>::move(stack&& rhs) noexcept
{
uint64_t i{0};
Expand Down
2 changes: 1 addition & 1 deletion iceoryx_hoofs/cli/include/iox/cli/arguments.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace cli
class Arguments
{
public:
enum class Error
enum class Error : uint8_t
{
UNABLE_TO_CONVERT_VALUE,
NO_SUCH_VALUE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ inline bool MpmcLockFreeQueue<ElementType, Capacity>::tryPush(const ElementType&
}

template <typename ElementType, uint64_t Capacity>
// NOLINTNEXTLINE(cppcoreguidelines-rvalue-reference-param-not-moved) perfect forwarding is used
inline bool MpmcLockFreeQueue<ElementType, Capacity>::tryPush(ElementType&& value) noexcept
{
uint64_t index{0};
Expand Down Expand Up @@ -120,6 +121,7 @@ inline iox::optional<ElementType> MpmcLockFreeQueue<ElementType, Capacity>::push
}

template <typename ElementType, uint64_t Capacity>
// NOLINTNEXTLINE(cppcoreguidelines-rvalue-reference-param-not-moved) perfect forwarding is used
inline iox::optional<ElementType> MpmcLockFreeQueue<ElementType, Capacity>::push(ElementType&& value) noexcept
{
return pushImpl(std::forward<ElementType>(value));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ inline bool MpmcResizeableLockFreeQueue<ElementType, MaxCapacity>::setCapacity(c

template <typename ElementType, uint64_t MaxCapacity>
template <typename Function, typename>
inline bool MpmcResizeableLockFreeQueue<ElementType, MaxCapacity>::setCapacity(const uint64_t newCapacity,
Function&& removeHandler) noexcept
inline bool MpmcResizeableLockFreeQueue<ElementType, MaxCapacity>::setCapacity(
const uint64_t newCapacity,
// NOLINTNEXTLINE(cppcoreguidelines-missing-std-forward) false positive, this is used as a universal reference
Function&& removeHandler) noexcept
{
if (newCapacity > MAX_CAPACITY)
{
Expand Down Expand Up @@ -121,9 +123,10 @@ MpmcResizeableLockFreeQueue<ElementType, MaxCapacity>::increaseCapacity(const ui

template <typename ElementType, uint64_t MaxCapacity>
template <typename Function>
inline uint64_t
MpmcResizeableLockFreeQueue<ElementType, MaxCapacity>::decreaseCapacity(const uint64_t toDecrease,
Function&& removeHandler) noexcept
inline uint64_t MpmcResizeableLockFreeQueue<ElementType, MaxCapacity>::decreaseCapacity(
const uint64_t toDecrease,
// NOLINTNEXTLINE(cppcoreguidelines-missing-std-forward) false positive, this is used as a universal reference
Function&& removeHandler) noexcept
{
uint64_t decreased = 0U;
while (decreased < toDecrease)
Expand Down Expand Up @@ -191,6 +194,7 @@ iox::optional<ElementType> inline MpmcResizeableLockFreeQueue<ElementType, MaxCa

template <typename ElementType, uint64_t MaxCapacity>
inline iox::optional<ElementType>
// NOLINTNEXTLINE(cppcoreguidelines-rvalue-reference-param-not-moved) perfect forwarding is used
MpmcResizeableLockFreeQueue<ElementType, MaxCapacity>::push(ElementType&& value) noexcept
{
return pushImpl(std::forward<ElementType>(value));
Expand Down
7 changes: 5 additions & 2 deletions iceoryx_hoofs/container/include/iox/detail/forward_list.inl
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ inline bool forward_list<T, Capacity>::push_front(const T& data) noexcept
}

template <typename T, uint64_t Capacity>
// NOLINTNEXTLINE(cppcoreguidelines-rvalue-reference-param-not-moved) perfect forwarding is used
inline bool forward_list<T, Capacity>::push_front(T&& data) noexcept
{
auto sizeBeforePush = m_size;
Expand All @@ -380,8 +381,10 @@ inline typename forward_list<T, Capacity>::iterator forward_list<T, Capacity>::i
}

template <typename T, uint64_t Capacity>
inline typename forward_list<T, Capacity>::iterator forward_list<T, Capacity>::insert_after(const_iterator citer,
T&& data) noexcept
inline typename forward_list<T, Capacity>::iterator forward_list<T, Capacity>::insert_after(
const_iterator citer,
// NOLINTNEXTLINE(cppcoreguidelines-rvalue-reference-param-not-moved) perfect forwarding is used
T&& data) noexcept
{
return emplace_after(citer, std::forward<T>(data));
}
Expand Down
49 changes: 26 additions & 23 deletions iceoryx_hoofs/container/include/iox/detail/list.inl
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,28 @@

namespace iox
{
/// @NOLINTJUSTIFICATION m_data fields are explicitly initialized whenever a new element is inserted
/// into the list
/// @NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init,hicpp-member-init)
// NOLINTJUSTIFICATION m_data fields are explicitly initialized whenever a new element is inserted
// into the list
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init,hicpp-member-init)
template <typename T, uint64_t Capacity>
inline list<T, Capacity>::list() noexcept
{
init();
}

/// @NOLINTJUSTIFICATION m_data fields are explicitly initialized whenever a new element is inserted
/// into the list
/// @NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init,hicpp-member-init)
// NOLINTJUSTIFICATION m_data fields are explicitly initialized whenever a new element is inserted
// into the list
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init,hicpp-member-init)
template <typename T, uint64_t Capacity>
inline list<T, Capacity>::list(const list& rhs) noexcept
{
init();
*this = rhs;
}

/// @NOLINTJUSTIFICATION m_data fields are explicitly initialized whenever a new element is inserted
/// into the list
/// @NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init,hicpp-member-init)
// NOLINTJUSTIFICATION m_data fields are explicitly initialized whenever a new element is inserted
// into the list
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init,hicpp-member-init)
template <typename T, uint64_t Capacity>
inline list<T, Capacity>::list(list&& rhs) noexcept
{
Expand Down Expand Up @@ -371,6 +371,7 @@ inline bool list<T, Capacity>::push_front(const T& data) noexcept
}

template <typename T, uint64_t Capacity>
// NOLINTNEXTLINE(cppcoreguidelines-rvalue-reference-param-not-moved) perfect forwarding is used
inline bool list<T, Capacity>::push_front(T&& data) noexcept
{
auto sizeBeforePush = m_size;
Expand All @@ -394,6 +395,7 @@ inline bool list<T, Capacity>::push_back(const T& data) noexcept
}

template <typename T, uint64_t Capacity>
// NOLINTNEXTLINE(cppcoreguidelines-rvalue-reference-param-not-moved) perfect forwarding is used
inline bool list<T, Capacity>::push_back(T&& data) noexcept
{
auto sizeBeforePush = m_size;
Expand Down Expand Up @@ -427,6 +429,7 @@ inline typename list<T, Capacity>::iterator list<T, Capacity>::insert(const_iter
}

template <typename T, uint64_t Capacity>
// NOLINTNEXTLINE(cppcoreguidelines-rvalue-reference-param-not-moved) perfect forwarding is used
inline typename list<T, Capacity>::iterator list<T, Capacity>::insert(const_iterator citer, T&& data) noexcept
{
return emplace(citer, std::forward<T>(data));
Expand Down Expand Up @@ -466,9 +469,9 @@ template <bool IsConstIterator>
inline typename list<T, Capacity>::template IteratorBase<IsConstIterator>&
list<T, Capacity>::IteratorBase<IsConstIterator>::operator=(const IteratorBase<false>& rhs) noexcept
{
/// @NOLINTJUSTIFICATION ensure that this and rhs are not the same object without taking the type into account
/// required since it is possible to assign a non const iterator to a const iterator
/// @NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
// NOLINTJUSTIFICATION ensure that this and rhs are not the same object without taking the type into account
// required since it is possible to assign a non const iterator to a const iterator
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
if (reinterpret_cast<const void*>(this) != reinterpret_cast<const void*>(&rhs))
{
m_list = rhs.m_list;
Expand Down Expand Up @@ -594,9 +597,9 @@ inline const typename list<T, Capacity>::size_type& list<T, Capacity>::getPrevId
template <typename T, uint64_t Capacity>
inline typename list<T, Capacity>::size_type& list<T, Capacity>::getPrevIdx(const size_type idx) noexcept
{
/// @NOLINTJUSTIFICATION const_cast avoids code duplication, is safe since the constness of the return value is
/// restored
/// @NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast)
// NOLINTJUSTIFICATION const_cast avoids code duplication, is safe since the constness of the return value is
// restored
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast)
return const_cast<size_type&>(const_cast<const list<T, Capacity>*>(this)->getPrevIdx(idx));
}

Expand All @@ -608,9 +611,9 @@ inline const typename list<T, Capacity>::size_type& list<T, Capacity>::getNextId
template <typename T, uint64_t Capacity>
inline typename list<T, Capacity>::size_type& list<T, Capacity>::getNextIdx(const size_type idx) noexcept
{
/// @NOLINTJUSTIFICATION const_cast avoids code duplication, is safe since the constness of the return value is
/// restored
/// @NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast)
// NOLINTJUSTIFICATION const_cast avoids code duplication, is safe since the constness of the return value is
// restored
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast)
return const_cast<size_type&>(const_cast<const list<T, Capacity>*>(this)->getNextIdx(idx));
}

Expand Down Expand Up @@ -656,17 +659,17 @@ inline const T* list<T, Capacity>::getDataPtrFromIdx(const size_type idx) const
{
IOX_ENFORCE(isValidElementIdx(idx), "invalid list element");

/// @NOLINTJUSTIFICATION provide type safe access to the encapsulated untyped m_data array
/// @NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
// NOLINTJUSTIFICATION provide type safe access to the encapsulated untyped m_data array
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
return &(reinterpret_cast<const T*>(&m_data)[idx]);
}

template <typename T, uint64_t Capacity>
inline T* list<T, Capacity>::getDataPtrFromIdx(const size_type idx) noexcept
{
/// @NOLINTJUSTIFICATION const_cast avoids code duplication, is safe since the constness of the return value is
/// restored
/// @NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast)
// NOLINTJUSTIFICATION const_cast avoids code duplication, is safe since the constness of the return value is
// restored
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast)
return const_cast<T*>(const_cast<const list<T, Capacity>*>(this)->getDataPtrFromIdx(idx));
}

Expand Down
1 change: 1 addition & 0 deletions iceoryx_hoofs/container/include/iox/detail/vector.inl
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ inline bool vector<T, Capacity>::push_back(const T& value) noexcept
}

template <typename T, uint64_t Capacity>
// NOLINTNEXTLINE(cppcoreguidelines-rvalue-reference-param-not-moved) perfect forwarding is used
inline bool vector<T, Capacity>::push_back(T&& value) noexcept
{
// AXIVION Next Construct AutosarC++19_03-A18.9.2: we use idiomatic perfect forwarding
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ template <typename T, uint64_t CAPACITY>
class FixedPositionContainer final
{
private:
enum class IterMutability
enum class IterMutability : uint8_t
{
ITER_MUT,
ITER_CONST
Expand Down
6 changes: 3 additions & 3 deletions iceoryx_hoofs/container/include/iox/list.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,9 @@ class list

/// @brief construct a const_iterator from an iterator
/// @param[in] iter is the iterator which will deliver list and index info for the const_iterator
/// @NOLINTJUSTIFICATION conversion from non const iterator to const iterator follows the
/// STL behavior and should be allowed
/// @NOLINTNEXTLINE(hicpp-explicit-conversions)
// NOLINTJUSTIFICATION conversion from non const iterator to const iterator follows the
// STL behavior and should be allowed
// NOLINTNEXTLINE(hicpp-explicit-conversions)
IteratorBase(const IteratorBase<false>& iter) noexcept;

/// @brief assigns a const_iterator from an iterator; needs to be implemented because the copy c'tor is also
Expand Down
3 changes: 2 additions & 1 deletion iceoryx_hoofs/design/include/iox/move_and_copy_helper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@
#ifndef IOX_HOOFS_DESIGN_MOVE_AND_COPY_HELPER_HPP
#define IOX_HOOFS_DESIGN_MOVE_AND_COPY_HELPER_HPP

#include <cstdint>
#include <functional>
#include <utility>

namespace iox
{

enum class MoveAndCopyOperations
enum class MoveAndCopyOperations : uint8_t
{
CopyConstructor,
CopyAssignment,
Expand Down
4 changes: 2 additions & 2 deletions iceoryx_hoofs/design/include/iox/newtype.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class NewType : public Policies<Derived, NewType<Derived, T, Policies...>>...
{
protected:
/// 'ProtectedConstructor_t' is a compile time variable to select the correct constructors
/// @NOLINTNEXTLINE(hicpp-named-parameter, readability-named-parameter)
// NOLINTNEXTLINE(hicpp-named-parameter, readability-named-parameter)
constexpr NewType(newtype::internal::ProtectedConstructor_t, const T& rhs) noexcept;

/// @brief copy constructor
Expand Down Expand Up @@ -156,7 +156,7 @@ class NewType : public Policies<Derived, NewType<Derived, T, Policies...>>...
// AXIVION Next Construct AutosarC++19_03-M16.0.6 : brackets around macro parameter would lead in this case to compile
// time failures
// AXIVION Next Construct AutosarC++19_03-A16.0.1 : macro is used to reduce boilerplate code for 'NewType'
/// @NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
#define IOX_NEW_TYPE(TypeName, Type, ...) \
struct TypeName : public iox::NewType<TypeName, Type, __VA_ARGS__> \
{ \
Expand Down
3 changes: 2 additions & 1 deletion iceoryx_hoofs/filesystem/include/iox/file_reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#ifndef IOX_HOOFS_FILESYSTEM_FILE_READER_HPP
#define IOX_HOOFS_FILESYSTEM_FILE_READER_HPP

#include <cstdint>
#include <fstream>

namespace iox
Expand All @@ -40,7 +41,7 @@ class FileReader
public:
/// Error handling strategy. Ignore continues execution as if nothing happened. Inform continues, but prints an
/// error message. Terminate causes the process to exit.
enum class ErrorMode
enum class ErrorMode : uint8_t
{
Ignore,
Inform,
Expand Down
6 changes: 3 additions & 3 deletions iceoryx_hoofs/filesystem/include/iox/filesystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ constexpr char ASCII_UNDERSCORE{'_'};
} // namespace internal
// AXIVION ENABLE STYLE AutosarC++19_03-A3.9.1

enum class RelativePathComponents : std::uint32_t
enum class RelativePathComponents : uint8_t
{
REJECT,
ACCEPT
Expand Down Expand Up @@ -91,15 +91,15 @@ template <uint64_t StringCapacity>
bool doesEndWithPathSeparator(const string<StringCapacity>& name) noexcept;


enum class AccessMode : uint64_t
enum class AccessMode : uint8_t
{
READ_ONLY = 0U,
READ_WRITE = 1U,
WRITE_ONLY = 2U
};

/// @brief describes how the shared memory is opened or created
enum class OpenMode : uint64_t
enum class OpenMode : uint8_t
{
/// @brief creates the shared memory, if it exists already the construction will fail
EXCLUSIVE_CREATE = 0U,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ template <class ReturnType, class... ArgTypes>
template <typename CallableType, typename>
// AXIVION Next Construct AutosarC++19_03-A12.1.5 : Other c'tors can't be used as delegating c'tor
// AXIVION Next Construct AutosarC++19_03-A8.4.6 : Only ArgTypes needs to be forwarded
// NOLINTNEXTLINE(cppcoreguidelines-missing-std-forward)
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
Expand Down
Loading
Loading