ETLCPP / etl

Embedded Template Library
https://www.etlcpp.com
MIT License
2.04k stars 371 forks source link

Error using etl::optional::emplace with objects with const members #878

Closed Forlautboy closed 2 months ago

Forlautboy commented 2 months ago

We encountered a situation where using etl::optional::emplace with a object with a const member leeds to the following compiler error:

"error: non-static const member 'const int Test::m_i', cannot use default assignment operator"

The following link provides a minimal Example: https://godbolt.org/z/bYEEYvKqM

It seams like etl::optional::emplace implements special case where assignement ist executed instead of emplacement. Whats also interesting is, that the standard-library posesses simular behaviour with C++17.

jwellbelove commented 2 months ago

It seems that for C++17 it cannot implicitly convert from int to Test with the etl/std::forward in the function etl/std::construct_at. This seems to have been fixed in C++20.

The only way around this is to add a constructor to Test.