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

Declared but undefined copy assignment operator for iox::expected #2216

Closed
pbarone-latai opened this issue Mar 7, 2024 · 1 comment · Fixed by #2218
Closed

Declared but undefined copy assignment operator for iox::expected #2216

pbarone-latai opened this issue Mar 7, 2024 · 1 comment · Fixed by #2218
Assignees

Comments

@pbarone-latai
Copy link
Contributor

pbarone-latai commented Mar 7, 2024

Required information

Operating system:
Ubuntu 20.04.6 LTS

Compiler version:
Clang 11

Eclipse iceoryx version:
master

Observed result or behaviour:

iox::expected has a copy and a move assignment operator declared here:

/// @brief calls the copy assignment operator of the contained success value
/// or the error value - depending on what is stored in the expected
expected& operator=(const expected&) noexcept;
/// @brief calls the move assignment operator of the contained success value
/// or the error value - depending on what is stored in the expected
/// @note The move assignment operator does not explicitly invalidate the moved-from object but relies on the move
/// assignment operator of ValueType or ErrorType to correctly invalidate the stored object
expected& operator=(expected&& rhs) noexcept;

however, only the move assignment operator is defined

template <typename ValueType, typename ErrorType>
inline expected<ValueType, ErrorType>&
expected<ValueType, ErrorType>::operator=(expected<ValueType, ErrorType>&& rhs) noexcept
{
// AXIVION Next Construct AutosarC++19_03-M0.1.2, AutosarC++19_03-M0.1.9, FaultDetection-DeadBranches : False positive. Check needed to avoid self assignment.
if (this != &rhs)
{
m_store = std::move(rhs.m_store);
}
return *this;
}

As a result, a linker error is generated when attempting to run the following snippet ...

TEST_CASE("Test")
{
  iox::expected<void, int> a = iox::ok();
  iox::expected<void, int> b = iox::err(1);
  a = b;
}
ld.lld: error: undefined symbol: iox::expected<void, int>::operator=(iox::expected<void, int> const&)
>>> referenced by estimator_lib_test.cc
>>>               <REDACTED PATH>test.o:(C_A_T_C_H_T_E_S_T_2())
clang-11: error: linker command failed with exit code 1 (use -v to see invocation)

Expected result or behaviour:
No compiler error

Conditions where it occurred / Performed steps:
See above

@elfenpiff
Copy link
Contributor

@pbarone-latai Whoopsie. How did that happen.

Thanks for the finding, I will take care of this.

@elfenpiff elfenpiff self-assigned this Mar 7, 2024
elfenpiff added a commit to elfenpiff/iceoryx that referenced this issue Mar 11, 2024
elfenpiff added a commit that referenced this issue Mar 11, 2024
…nt-operator-for-expected

iox-#2216 Implement missing copy assignment operator for expected
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants