Skip to content

Commit

Permalink
iox-#1067 Fix clang-tidy warnings
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Eltzschig <[email protected]>
  • Loading branch information
elfenpiff committed Apr 4, 2022
1 parent be68cad commit e1929cf
Show file tree
Hide file tree
Showing 12 changed files with 120 additions and 113 deletions.
52 changes: 27 additions & 25 deletions iceoryx_hoofs/include/iceoryx_hoofs/cxx/type_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ using add_const_conditionally_t = typename add_const_conditionally<T, C>::type;
///
/// @brief Helper value to bind a static_assert to a type
/// @code
/// static_assert(always_false_v<Foo>, "Not implemented for the given type!");
/// static_assert(ALWAYS_FALSE_V<Foo>, "Not implemented for the given type!");
/// @endcode
///
template <typename>
constexpr bool always_false_v = false;
constexpr bool ALWAYS_FALSE_V = false;

// windows defines __cplusplus as 199711L
#if __cplusplus < 201703L && !defined(_WIN32)
Expand All @@ -80,13 +80,14 @@ struct is_invocable

// This is chosen if Callable(ArgTypes) does not resolve to a valid type.
template <typename C, typename... As>
static constexpr std::false_type test(...) noexcept
static constexpr std::false_type test(...) noexcept // NOLINT, required to accept everything else
{
return {};
}

// Test with nullptr as this can stand in for a pointer to any type.
static constexpr bool value = decltype(test<Callable, ArgTypes...>(nullptr))::value;
static constexpr bool value = // NOLINT, we want to be compatible with stl
decltype(test<Callable, ArgTypes...>(nullptr))::value;
};

///
Expand All @@ -106,13 +107,14 @@ struct is_invocable_r
}

template <typename C, typename... As>
static constexpr std::false_type test(...) noexcept
static constexpr std::false_type test(...) noexcept // NOLINT, required to accept everything else
{
return {};
}

// Test with nullptr as this can stand in for a pointer to any type.
static constexpr bool value = decltype(test<Callable, ArgTypes...>(nullptr))::value;
static constexpr bool value = // NOLINT, we want to be compatible with stl
decltype(test<Callable, ArgTypes...>(nullptr))::value;
};

///
Expand All @@ -133,108 +135,108 @@ using void_t = void;


//////////////////
/// BEGIN TypeInfo
/// BEGIN type_info
//////////////////

/// @brief Provides a translation from a type into its human readable name
template <typename T>
struct TypeInfo
struct type_info
{
static constexpr const char NAME[] = "unknown type";
};
template <typename T>
constexpr const char TypeInfo<T>::NAME[];
constexpr const char type_info<T>::NAME[];

template <uint64_t>
class string;

template <uint64_t N>
struct TypeInfo<iox::cxx::string<N>>
struct type_info<iox::cxx::string<N>>
{
static constexpr const char NAME[] = "string";
};
template <uint64_t N>
constexpr const char TypeInfo<iox::cxx::string<N>>::NAME[];
constexpr const char type_info<iox::cxx::string<N>>::NAME[];

template <>
struct TypeInfo<int8_t>
struct type_info<int8_t>
{
static constexpr const char NAME[] = "int8_t";
};

template <>
struct TypeInfo<int16_t>
struct type_info<int16_t>
{
static constexpr const char NAME[] = "int16_t";
};

template <>
struct TypeInfo<int32_t>
struct type_info<int32_t>
{
static constexpr const char NAME[] = "int32_t";
};

template <>
struct TypeInfo<int64_t>
struct type_info<int64_t>
{
static constexpr const char NAME[] = "int64_t";
};

template <>
struct TypeInfo<uint8_t>
struct type_info<uint8_t>
{
static constexpr const char NAME[] = "uint8_t";
};

template <>
struct TypeInfo<uint16_t>
struct type_info<uint16_t>
{
static constexpr const char NAME[] = "uint16_t";
};

template <>
struct TypeInfo<uint32_t>
struct type_info<uint32_t>
{
static constexpr const char NAME[] = "uint32_t";
};

template <>
struct TypeInfo<uint64_t>
struct type_info<uint64_t>
{
static constexpr const char NAME[] = "uint64_t";
};

template <>
struct TypeInfo<bool>
struct type_info<bool>
{
static constexpr const char NAME[] = "bool";
};

template <>
struct TypeInfo<char>
struct type_info<char>
{
static constexpr const char NAME[] = "char";
};

template <>
struct TypeInfo<float>
struct type_info<float>
{
static constexpr const char NAME[] = "float";
};

template <>
struct TypeInfo<double>
struct type_info<double>
{
static constexpr const char NAME[] = "double";
};

template <>
struct TypeInfo<long double>
struct type_info<long double>
{
static constexpr const char NAME[] = "long double";
};
//////////////////
/// END TypeInfo
/// END type_info
//////////////////
} // namespace cxx
} // namespace iox
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ inline bool isValidFilePath(const string<StringCapacity>& name) noexcept
template <typename F, typename T>
constexpr T from(const F) noexcept
{
static_assert(always_false_v<F> && always_false_v<T>, "Conversion for the specified types is not implemented!\
static_assert(ALWAYS_FALSE_V<F> && ALWAYS_FALSE_V<T>, "Conversion for the specified types is not implemented!\
Please specialize `template <typename F, typename T> constexpr T from(const F) noexcept`!");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,12 @@ class storable_function<StorageType, signature<ReturnType, Args...>>
typename = typename std::enable_if<std::is_class<Functor>::value
&& is_invocable_r<ReturnType, Functor, Args...>::value,
void>::type>
storable_function(const Functor& functor) noexcept;
storable_function(const Functor& functor) noexcept; // NOLINT, we want that lambdas etc. are implicitly convertable
// to a storable function

/// @brief construct from function pointer (including static functions)
storable_function(ReturnType (*function)(Args...)) noexcept;
storable_function(ReturnType (*function)(Args...)) noexcept; // NOLINT, we want that free functions are
// implicitly convertable to a storable function

/// @brief construct from object reference and member function
/// only a pointer to the object is stored for the call
Expand Down Expand Up @@ -154,6 +156,7 @@ class storable_function<StorageType, signature<ReturnType, Args...>>
operations& operator=(const operations& other) noexcept = default;
operations(operations&& other) noexcept = default;
operations& operator=(operations&& other) noexcept = default;
~operations() = default;

void copy(const storable_function& src, storable_function& dest) noexcept;

Expand All @@ -178,7 +181,7 @@ class storable_function<StorageType, signature<ReturnType, Args...>>
typename = typename std::enable_if<std::is_class<Functor>::value
&& is_invocable_r<ReturnType, Functor, Args...>::value,
void>::type>
void storeFunctor(const Functor& functor) noexcept;
void store_functor(const Functor& functor) noexcept;

bool empty() const noexcept;

Expand All @@ -195,11 +198,11 @@ class storable_function<StorageType, signature<ReturnType, Args...>>
template <typename CallableType>
static ReturnType invoke(void* callable, Args&&... args);

static void copyFreeFunction(const storable_function& src, storable_function& dest) noexcept;
static void copy_free_function(const storable_function& src, storable_function& dest) noexcept;

static void moveFreeFunction(storable_function& src, storable_function& dest) noexcept;
static void move_free_function(storable_function& src, storable_function& dest) noexcept;

static ReturnType invokeFreeFunction(void* callable, Args&&... args);
static ReturnType invoke_free_function(void* callable, Args&&... args);
};

/// @brief swap two storable functions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@ template <typename S, typename ReturnType, typename... Args>
template <typename Functor, typename>
storable_function<S, signature<ReturnType, Args...>>::storable_function(const Functor& functor) noexcept
{
storeFunctor(functor);
store_functor(functor);
}

template <typename S, typename ReturnType, typename... Args>
storable_function<S, signature<ReturnType, Args...>>::storable_function(ReturnType (*function)(Args...)) noexcept
{
if (function)
{
m_invoker = invokeFreeFunction;
m_invoker = invoke_free_function;
m_callable = reinterpret_cast<void*>(function);
m_operations.copyFunction = copyFreeFunction;
m_operations.moveFunction = moveFreeFunction;
m_operations.copyFunction = copy_free_function;
m_operations.moveFunction = move_free_function;
// destroy is not needed for free functions
}
}
Expand All @@ -51,7 +51,7 @@ storable_function<S, signature<ReturnType, Args...>>::storable_function(T& objec
{
auto p = &object;
auto functor = [p, method](Args... args) -> ReturnType { return (*p.*method)(std::forward<Args>(args)...); };
storeFunctor(functor);
store_functor(functor);
}

template <typename S, typename ReturnType, typename... Args>
Expand All @@ -61,7 +61,7 @@ storable_function<S, signature<ReturnType, Args...>>::storable_function(const T&
{
auto p = &object;
auto functor = [p, method](Args... args) -> ReturnType { return (*p.*method)(std::forward<Args>(args)...); };
storeFunctor(functor);
store_functor(functor);
}

template <typename S, typename ReturnType, typename... Args>
Expand Down Expand Up @@ -154,7 +154,7 @@ bool storable_function<S, signature<ReturnType, Args...>>::empty() const noexcep

template <typename S, typename ReturnType, typename... Args>
template <typename Functor, typename>
void storable_function<S, signature<ReturnType, Args...>>::storeFunctor(const Functor& functor) noexcept
void storable_function<S, signature<ReturnType, Args...>>::store_functor(const Functor& functor) noexcept
{
using StoredType = typename std::remove_reference<Functor>::type;
auto ptr = m_storage.template allocate<StoredType>();
Expand Down Expand Up @@ -257,16 +257,16 @@ void storable_function<S, signature<ReturnType, Args...>>::destroy(storable_func
}

template <typename S, typename ReturnType, typename... Args>
void storable_function<S, signature<ReturnType, Args...>>::copyFreeFunction(const storable_function& src,
storable_function& dest) noexcept
void storable_function<S, signature<ReturnType, Args...>>::copy_free_function(const storable_function& src,
storable_function& dest) noexcept
{
dest.m_invoker = src.m_invoker;
dest.m_callable = src.m_callable;
}

template <typename S, typename ReturnType, typename... Args>
void storable_function<S, signature<ReturnType, Args...>>::moveFreeFunction(storable_function& src,
storable_function& dest) noexcept
void storable_function<S, signature<ReturnType, Args...>>::move_free_function(storable_function& src,
storable_function& dest) noexcept
{
dest.m_invoker = src.m_invoker;
dest.m_callable = src.m_callable;
Expand All @@ -282,7 +282,7 @@ ReturnType storable_function<S, signature<ReturnType, Args...>>::invoke(void* ca
}

template <typename S, typename ReturnType, typename... Args>
ReturnType storable_function<S, signature<ReturnType, Args...>>::invokeFreeFunction(void* callable, Args&&... args)
ReturnType storable_function<S, signature<ReturnType, Args...>>::invoke_free_function(void* callable, Args&&... args)
{
return (reinterpret_cast<ReturnType (*)(Args...)>(callable))(std::forward<Args>(args)...);
}
Expand Down
10 changes: 5 additions & 5 deletions iceoryx_hoofs/include/iceoryx_hoofs/internal/cxx/string.inl
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ inline std::ostream& operator<<(std::ostream& stream, const string<Capacity>& st
template <uint64_t Capacity>
inline bool string<Capacity>::operator==(const char* const) const noexcept
{
static_assert(cxx::always_false_v<string<Capacity>>,
static_assert(cxx::ALWAYS_FALSE_V<string<Capacity>>,
"The equality operator for fixed string and char pointer is disabled, because it may lead to "
"undefined behavior if the char array is not null-terminated. Please convert the char array to a "
"fixed string with string(TruncateToCapacity_t, const char* const other, const uint64_t count) "
Expand All @@ -379,7 +379,7 @@ inline bool string<Capacity>::operator==(const char* const) const noexcept
template <uint64_t Capacity>
inline bool string<Capacity>::operator!=(const char* const) const noexcept
{
static_assert(cxx::always_false_v<string<Capacity>>,
static_assert(cxx::ALWAYS_FALSE_V<string<Capacity>>,
"The inequality operator for fixed string and char pointer is disabled, because it may lead to "
"undefined behavior if the char array is not null-terminated. Please convert the char array to a "
"fixed string with string(TruncateToCapacity_t, const char* const other, const uint64_t count) "
Expand All @@ -390,7 +390,7 @@ inline bool string<Capacity>::operator!=(const char* const) const noexcept
template <uint64_t Capacity>
inline bool operator==(const char* const, const string<Capacity>&) noexcept
{
static_assert(cxx::always_false_v<string<Capacity>>,
static_assert(cxx::ALWAYS_FALSE_V<string<Capacity>>,
"The equality operator for char pointer and fixed string is disabled, because it may lead to "
"undefined behavior if the char array is not null-terminated. Please convert the char array to a "
"fixed string with string(TruncateToCapacity_t, const char* const other, const uint64_t count) "
Expand All @@ -401,7 +401,7 @@ inline bool operator==(const char* const, const string<Capacity>&) noexcept
template <uint64_t Capacity>
inline bool operator!=(const char* const, const string<Capacity>&) noexcept
{
static_assert(cxx::always_false_v<string<Capacity>>,
static_assert(cxx::ALWAYS_FALSE_V<string<Capacity>>,
"The inequality operator for char pointer and fixed string is disabled, because it may lead to "
"undefined behavior if the char array is not null-terminated. Please convert the char array to a "
"fixed string with string(TruncateToCapacity_t, const char* const other, const uint64_t count) "
Expand All @@ -413,7 +413,7 @@ template <uint64_t Capacity>
template <typename T>
inline string<Capacity>& string<Capacity>::operator+=(const T&) noexcept
{
static_assert(cxx::always_false_v<string<Capacity>>,
static_assert(cxx::ALWAYS_FALSE_V<string<Capacity>>,
"operator += is not supported by cxx::string, please use append or unsafe_append instead");
return *this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ inline T addEntry(const CommandLineParser& parser,
internal::cmdEntries_t& entries,
internal::cmdAssignments_t& assignments)
{
entries.emplace_back(CommandLineParser::entry_t{
entries.emplace_back(CommandLineParser::Entry{
shortName,
name,
description,
argumentType,
{cxx::TypeInfo<T>::NAME},
{cxx::type_info<T>::NAME},
CommandLineOptions::value_t(cxx::TruncateToCapacity, cxx::convert::toString(defaultValue))});
assignments.emplace_back([&parser, &value, &entries, index = entries.size() - 1](CommandLineOptions& options) {
extractValue(parser, value, entries, index, options);
Expand All @@ -94,7 +94,7 @@ inline bool addEntry(const CommandLineParser& parser,
internal::cmdEntries_t& entries,
internal::cmdAssignments_t& assignments)
{
entries.emplace_back(CommandLineParser::entry_t{
entries.emplace_back(CommandLineParser::Entry{
shortName,
name,
description,
Expand Down
Loading

0 comments on commit e1929cf

Please sign in to comment.