Skip to content

Commit a0f1b8a

Browse files
[#2249] Fix clang warnings
1 parent 0f5a44a commit a0f1b8a

File tree

7 files changed

+188
-72
lines changed

7 files changed

+188
-72
lines changed

iceoryx_hoofs/container/include/iox/detail/fixed_position_container.inl

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,73 @@ template <typename T, uint64_t CAPACITY>
164164
template <MoveAndCopyOperations Opt, typename RhsType>
165165
inline void FixedPositionContainer<T, CAPACITY>::copy_and_move_impl(RhsType&& rhs) noexcept
166166
{
167+
// alias helper struct
168+
using Helper = MoveAndCopyHelper<Opt>;
169+
170+
constexpr bool is_ctor = Helper::is_ctor;
171+
constexpr bool is_move = Helper::is_move;
172+
173+
// status array is not yet initialized for constructor creation
174+
if (is_ctor)
175+
{
176+
for (IndexType i = 0; i < CAPACITY; ++i)
177+
{
178+
m_status[i] = SlotStatus::FREE;
179+
}
180+
}
181+
182+
IndexType i{Index::FIRST};
183+
auto rhs_it = (std::forward<RhsType>(rhs)).begin();
184+
185+
for (; rhs_it.to_index() != Index::INVALID; ++i, ++rhs_it)
186+
{
187+
if (m_status[i] == SlotStatus::USED)
188+
{
189+
// When the slot is in the 'USED' state, it is safe to proceed with either construction (ctor) or assignment
190+
// operation. Therefore, creation can be carried out according to the option specified by Opt.
191+
Helper::transfer(m_data[i], Helper::move_or_copy_it(rhs_it));
192+
}
193+
else
194+
{
195+
// When the slot is in the 'FREE' state, it is unsafe to proceed with assignment operation.
196+
// Therefore, we need to force helper to use ctor create to make sure that the 'FREE' slots get initialized.
197+
Helper::create_new(m_data[i], Helper::move_or_copy_it(rhs_it));
198+
}
199+
200+
m_status[i] = SlotStatus::USED;
201+
m_next[i] = static_cast<IndexType>(i + 1U);
202+
}
203+
204+
// reset rest
205+
for (; i < CAPACITY; ++i)
206+
{
207+
if (m_status[i] == SlotStatus::USED)
208+
{
209+
m_data[i].~T();
210+
}
211+
212+
m_status[i] = SlotStatus::FREE;
213+
214+
auto next = static_cast<IndexType>(i + 1U);
215+
m_next[i] = next;
216+
}
217+
218+
// correct m_next
219+
m_next[Index::LAST] = Index::INVALID;
220+
if (!rhs.empty())
221+
{
222+
m_next[rhs.m_size - 1] = Index::INVALID;
223+
}
224+
225+
m_begin_free = static_cast<IndexType>(rhs.m_size);
226+
m_begin_used = rhs.empty() ? Index::INVALID : Index::FIRST;
227+
m_size = rhs.m_size;
228+
229+
// reset rhs if is_move is true
230+
if (is_move)
231+
{
232+
rhs.clear();
233+
}
167234
}
168235
#endif
169236

iceoryx_hoofs/design/include/iox/detail/move_and_copy_helper.inl

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -75,19 +75,7 @@ template <MoveAndCopyOperations Opt>
7575
template <typename T, typename V>
7676
inline void MoveAndCopyHelper<Opt>::create_new(T& dest, V&& src) noexcept
7777
{
78-
if (is_move)
79-
{
80-
static_assert(std::is_rvalue_reference<decltype(src)>::value, "src should be rvalue reference");
81-
static_assert(std::is_convertible<V, T>::value, "src type is not convertible to dest type");
82-
new (&dest) T(std::forward<V>(src));
83-
}
84-
else
85-
{
86-
static_assert(std::is_lvalue_reference<decltype(src)>::value, "src should be lvalue reference");
87-
static_assert(std::is_const<std::remove_reference_t<decltype(src)>>::value, "src should have 'const' modifier");
88-
static_assert(std::is_convertible<V, T>::value, "src type is not convertible to dest type");
89-
new (&dest) T(src);
90-
}
78+
new (&dest) T(std::forward<V>(src));
9179
}
9280
#endif
9381

@@ -113,17 +101,7 @@ template <MoveAndCopyOperations Opt>
113101
template <typename T, typename V>
114102
inline void MoveAndCopyHelper<Opt>::assign(T& dest, V&& src) noexcept
115103
{
116-
if (is_move)
117-
{
118-
static_assert(std::is_rvalue_reference<decltype(src)>::value, "src should be rvalue reference");
119-
dest = std::forward<V>(src);
120-
}
121-
else
122-
{
123-
static_assert(std::is_lvalue_reference<decltype(src)>::value, "src should be lvalue reference");
124-
static_assert(std::is_const<std::remove_reference_t<decltype(src)>>::value, "src should have 'const' modifier");
125-
dest = src;
126-
}
104+
dest = std::forward<V>(src);
127105
}
128106
#endif
129107
} // namespace iox

iceoryx_hoofs/test/moduletests/test_vocabulary_string.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,12 @@ TYPED_TEST(stringTyped_test, UnsafeRawAccessCStringOfSizeCapaResultsInSizeCapa)
8383
using MyString = typename TestFixture::stringType;
8484
constexpr auto STRINGCAP = MyString::capacity();
8585
std::vector<char> testCharstring(STRINGCAP, 'M');
86-
#if (defined(__GNUC__))
86+
#if (defined(__GNUC__) && __GNUC__ >= 7 && !defined(__clang__))
8787
#pragma GCC diagnostic push
8888
#pragma GCC diagnostic ignored "-Warray-bounds"
8989
#endif
9090
testCharstring.emplace_back('\0');
91-
#if (defined(__GNUC__))
91+
#if (defined(__GNUC__) && __GNUC__ >= 7 && !defined(__clang__))
9292
#pragma GCC diagnostic pop
9393
#endif
9494
this->testSubject.unsafe_raw_access([&](char* str, const auto) -> uint64_t {

iceoryx_hoofs/test/moduletests/test_vocabulary_string_ctor_and_assign.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -727,13 +727,13 @@ TYPED_TEST(stringTyped_test, UnsafeAssignCStringOfSizeCapaResultsInSizeCapa)
727727
using MyString = typename TestFixture::stringType;
728728
constexpr auto STRINGCAP = MyString::capacity();
729729
std::vector<char> testCharstring(STRINGCAP, 'M');
730-
#if (defined(__GNUC__))
730+
#if (defined(__GNUC__) && __GNUC__ >= 7 && !defined(__clang__))
731731
#pragma GCC diagnostic push
732732
#pragma GCC diagnostic ignored "-Warray-bounds"
733733
#pragma GCC diagnostic ignored "-Wstringop-overflow"
734734
#endif
735735
testCharstring.emplace_back('\0');
736-
#if (defined(__GNUC__))
736+
#if (defined(__GNUC__) && __GNUC__ >= 7 && !defined(__clang__))
737737
#pragma GCC diagnostic pop
738738
#endif
739739
EXPECT_THAT(this->testSubject.unsafe_assign(testCharstring.data()), Eq(true));
@@ -746,13 +746,13 @@ TYPED_TEST(stringTyped_test, UnsafeAssignCStringOfSizeGreaterCapaResultsInSize0)
746746
using MyString = typename TestFixture::stringType;
747747
constexpr auto STRINGCAP = MyString::capacity();
748748
std::vector<char> testCharstring(STRINGCAP + 1U, 'M');
749-
#if (defined(__GNUC__))
749+
#if (defined(__GNUC__) && __GNUC__ >= 7 && !defined(__clang__))
750750
#pragma GCC diagnostic push
751751
#pragma GCC diagnostic ignored "-Warray-bounds"
752752
#pragma GCC diagnostic ignored "-Wstringop-overflow"
753753
#endif
754754
testCharstring.emplace_back('\0');
755-
#if (defined(__GNUC__))
755+
#if (defined(__GNUC__) && __GNUC__ >= 7 && !defined(__clang__))
756756
#pragma GCC diagnostic pop
757757
#endif
758758
EXPECT_THAT(this->testSubject.unsafe_assign(testCharstring.data()), Eq(false));
@@ -768,13 +768,13 @@ TYPED_TEST(stringTyped_test, UnsafeAssignOfInvalidCStringFails)
768768
using MyString = typename TestFixture::stringType;
769769
constexpr auto STRINGCAP = MyString::capacity();
770770
std::vector<char> testCharstring(STRINGCAP + 1U, 'M');
771-
#if (defined(__GNUC__))
771+
#if (defined(__GNUC__) && __GNUC__ >= 7 && !defined(__clang__))
772772
#pragma GCC diagnostic push
773773
#pragma GCC diagnostic ignored "-Warray-bounds"
774774
#pragma GCC diagnostic ignored "-Wstringop-overflow"
775775
#endif
776776
testCharstring.emplace_back('\0');
777-
#if (defined(__GNUC__))
777+
#if (defined(__GNUC__) && __GNUC__ >= 7 && !defined(__clang__))
778778
#pragma GCC diagnostic pop
779779
#endif
780780

iceoryx_hoofs/testing/include/iceoryx_hoofs/testing/fatal_failure.hpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,22 @@ namespace testing
4646
/// @param[in] testFunction This function will be executed as SUT and is expected to call the error handler
4747
/// @param[in] expectedError The error value which triggered the fatal failure
4848
/// @return true if a fatal failure occurs, false otherwise
49-
template <typename ErrorType>
49+
template <typename ErrorType,
50+
std::enable_if_t<!std::is_same<ErrorType, iox::er::FatalKind>::value
51+
&& !std::is_same<ErrorType, iox::er::EnforceViolationKind>::value
52+
&& !std::is_same<ErrorType, iox::er::AssertViolationKind>::value,
53+
bool> = true>
54+
bool IOX_EXPECT_FATAL_FAILURE(const function_ref<void()> testFunction, const ErrorType expectedError);
55+
56+
template <typename ErrorType, std::enable_if_t<std::is_same<ErrorType, iox::er::FatalKind>::value, bool> = true>
57+
bool IOX_EXPECT_FATAL_FAILURE(const function_ref<void()> testFunction, const ErrorType expectedError);
58+
59+
template <typename ErrorType,
60+
std::enable_if_t<std::is_same<ErrorType, iox::er::EnforceViolationKind>::value, bool> = true>
61+
bool IOX_EXPECT_FATAL_FAILURE(const function_ref<void()> testFunction, const ErrorType expectedError);
62+
63+
template <typename ErrorType,
64+
std::enable_if_t<std::is_same<ErrorType, iox::er::AssertViolationKind>::value, bool> = true>
5065
bool IOX_EXPECT_FATAL_FAILURE(const function_ref<void()> testFunction, const ErrorType expectedError);
5166

5267
/// @brief This function is used in cases no fatal failure is expected but could potentially occur. The function only

iceoryx_hoofs/testing/include/iceoryx_hoofs/testing/fatal_failure.inl

Lines changed: 87 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -24,71 +24,120 @@ namespace iox
2424
{
2525
namespace testing
2626
{
27-
#ifndef IOX_HOOFS_SUBSET
28-
template <typename ErrorType>
27+
#if (defined(__GNUC__))
28+
#pragma GCC diagnostic push
29+
#pragma GCC diagnostic ignored "-Wunused-parameter"
30+
#endif
31+
template <typename ErrorType, std::enable_if_t<std::is_same<ErrorType, iox::er::FatalKind>::value, bool>>
2932
// NOLINTJUSTIFICATION The complexity comes from the expanded macros; without the expansions the function is quite readable
3033
// NOLINTNEXTLINE(readability-function-size, readability-function-cognitive-complexity)
31-
inline bool IOX_EXPECT_FATAL_FAILURE(const function_ref<void()> testFunction,
32-
const ErrorType expectedError [[maybe_unused]])
34+
inline bool IOX_EXPECT_FATAL_FAILURE(const function_ref<void()> testFunction, const ErrorType expectedError)
3335
{
3436
iox::testing::ErrorHandler::instance().reset();
3537
runInTestThread([&] { testFunction(); });
3638
IOX_TESTING_EXPECT_PANIC();
3739
auto hasPanicked = iox::testing::hasPanicked();
3840

3941
auto hasExpectedError{false};
40-
if constexpr (std::is_same_v<ErrorType, iox::er::FatalKind>)
42+
hasExpectedError = hasPanicked;
43+
if (!hasExpectedError)
4144
{
42-
hasExpectedError = hasPanicked;
43-
if (!hasExpectedError)
44-
{
45-
IOX_LOG(Error, "Expected '" << iox::er::FatalKind::name << "' but it did not happen!");
46-
}
47-
}
48-
else if constexpr (std::is_same_v<ErrorType, iox::er::EnforceViolationKind>)
49-
{
50-
hasExpectedError = iox::testing::hasEnforceViolation();
51-
if (!hasExpectedError)
52-
{
53-
IOX_LOG(Error, "Expected '" << iox::er::EnforceViolationKind::name << "' but it did not happen!");
54-
}
55-
}
56-
else if constexpr (std::is_same_v<ErrorType, iox::er::AssertViolationKind>)
57-
{
58-
hasExpectedError = iox::testing::hasAssertViolation();
59-
if (!hasExpectedError)
60-
{
61-
IOX_LOG(Error, "Expected '" << iox::er::AssertViolationKind::name << "' but it did not happen!");
62-
}
63-
}
64-
else
65-
{
66-
hasExpectedError = iox::testing::hasError(expectedError);
67-
if (!hasExpectedError)
68-
{
69-
IOX_LOG(Error, "Expected an '" << expectedError << "' error but it did not happen!");
70-
}
45+
IOX_LOG(Error, "Expected '" << iox::er::FatalKind::name << "' but it did not happen!");
7146
}
7247

7348
EXPECT_TRUE(hasExpectedError);
7449
return hasExpectedError && hasPanicked;
7550
}
76-
#else
77-
template <typename ErrorType>
51+
#if (defined(__GNUC__))
52+
#pragma GCC diagnostic pop
53+
#endif
54+
55+
#if (defined(__GNUC__))
56+
#pragma GCC diagnostic push
57+
#pragma GCC diagnostic ignored "-Wunused-parameter"
58+
#endif
59+
template <typename ErrorType, std::enable_if_t<std::is_same<ErrorType, iox::er::EnforceViolationKind>::value, bool>>
7860
// NOLINTJUSTIFICATION The complexity comes from the expanded macros; without the expansions the function is quite readable
7961
// NOLINTNEXTLINE(readability-function-size, readability-function-cognitive-complexity)
62+
inline bool IOX_EXPECT_FATAL_FAILURE(const function_ref<void()> testFunction, const ErrorType expectedError)
63+
{
64+
iox::testing::ErrorHandler::instance().reset();
65+
runInTestThread([&] { testFunction(); });
66+
IOX_TESTING_EXPECT_PANIC();
67+
auto hasPanicked = iox::testing::hasPanicked();
68+
69+
auto hasExpectedError{false};
70+
hasExpectedError = iox::testing::hasEnforceViolation();
71+
if (!hasExpectedError)
72+
{
73+
IOX_LOG(Error, "Expected '" << iox::er::EnforceViolationKind::name << "' but it did not happen!");
74+
}
75+
76+
EXPECT_TRUE(hasExpectedError);
77+
return hasExpectedError && hasPanicked;
78+
}
79+
#if (defined(__GNUC__))
80+
#pragma GCC diagnostic pop
81+
#endif
82+
8083
#if (defined(__GNUC__))
8184
#pragma GCC diagnostic push
8285
#pragma GCC diagnostic ignored "-Wunused-parameter"
8386
#endif
87+
template <typename ErrorType, std::enable_if_t<std::is_same<ErrorType, iox::er::AssertViolationKind>::value, bool>>
88+
// NOLINTJUSTIFICATION The complexity comes from the expanded macros; without the expansions the function is quite readable
89+
// NOLINTNEXTLINE(readability-function-size, readability-function-cognitive-complexity)
8490
inline bool IOX_EXPECT_FATAL_FAILURE(const function_ref<void()> testFunction, const ErrorType expectedError)
91+
{
92+
iox::testing::ErrorHandler::instance().reset();
93+
runInTestThread([&] { testFunction(); });
94+
IOX_TESTING_EXPECT_PANIC();
95+
auto hasPanicked = iox::testing::hasPanicked();
96+
97+
auto hasExpectedError{false};
98+
hasExpectedError = iox::testing::hasAssertViolation();
99+
if (!hasExpectedError)
100+
{
101+
IOX_LOG(Error, "Expected '" << iox::er::AssertViolationKind::name << "' but it did not happen!");
102+
}
103+
104+
EXPECT_TRUE(hasExpectedError);
105+
return hasExpectedError && hasPanicked;
106+
}
85107
#if (defined(__GNUC__))
86108
#pragma GCC diagnostic pop
87109
#endif
110+
111+
#if (defined(__GNUC__))
112+
#pragma GCC diagnostic push
113+
#pragma GCC diagnostic ignored "-Wunused-parameter"
114+
#endif
115+
template <typename ErrorType,
116+
std::enable_if_t<!std::is_same<ErrorType, iox::er::FatalKind>::value
117+
&& !std::is_same<ErrorType, iox::er::EnforceViolationKind>::value
118+
&& !std::is_same<ErrorType, iox::er::AssertViolationKind>::value,
119+
bool>>
120+
// NOLINTJUSTIFICATION The complexity comes from the expanded macros; without the expansions the function is quite readable
121+
// NOLINTNEXTLINE(readability-function-size, readability-function-cognitive-complexity)
122+
inline bool IOX_EXPECT_FATAL_FAILURE(const function_ref<void()> testFunction, const ErrorType expectedError)
88123
{
89-
// TODO
90-
return true;
124+
iox::testing::ErrorHandler::instance().reset();
125+
runInTestThread([&] { testFunction(); });
126+
IOX_TESTING_EXPECT_PANIC();
127+
auto hasPanicked = iox::testing::hasPanicked();
128+
129+
auto hasExpectedError{false};
130+
hasExpectedError = iox::testing::hasError(expectedError);
131+
if (!hasExpectedError)
132+
{
133+
IOX_LOG(Error, "Expected an '" << expectedError << "' error but it did not happen!");
134+
}
135+
136+
EXPECT_TRUE(hasExpectedError);
137+
return hasExpectedError && hasPanicked;
91138
}
139+
#if (defined(__GNUC__))
140+
#pragma GCC diagnostic pop
92141
#endif
93142

94143
inline bool IOX_EXPECT_NO_FATAL_FAILURE(const function_ref<void()> testFunction)

iceoryx_hoofs/utility/include/iox/detail/convert.inl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ inline iox::optional<TargetType> convert::from_string(const char* v) noexcept
7171
}
7272

7373
template <typename TargetType, typename std::enable_if_t<!is_iox_string<TargetType>::value, int>>
74-
inline iox::optional<TargetType> convert::from_string(const char* v) noexcept
74+
inline iox::optional<TargetType> convert::from_string(const char* v IOX_MAYBE_UNUSED) noexcept
7575
{
7676
static_assert(always_false_v<TargetType>,
7777
"For a conversion to 'std::string' please include 'iox/std_string_support.hpp'!\nConversion not "
@@ -411,11 +411,18 @@ inline bool convert::is_within_range(const SourceType& source_val) noexcept
411411
{
412412
return true;
413413
}
414+
#if (defined(__clang__))
415+
#pragma GCC diagnostic push
416+
#pragma GCC diagnostic ignored "-Wimplicit-int-float-conversion"
417+
#endif
414418
// should be normal or zero
415419
if (!std::isnormal(source_val) && (source_val != 0.0))
416420
{
417421
return false;
418422
}
423+
#if (defined(__clang__))
424+
#pragma GCC diagnostic pop
425+
#endif
419426
}
420427
// out of range (upper bound)
421428
if (source_val > std::numeric_limits<TargetType>::max())

0 commit comments

Comments
 (0)