zserio
zserio copied to clipboard
InplaceOptionalHolder isn't nothrow_move_constructible
Zserio version and language Zserio: 2.16.0 Language: C++
Describe the bug
static_assert(std::is_nothrow_move_constructible<zserio::InplaceOptionalHolder<int>>) fails. This is unexpected considering int is nothrow_move_constructible and causes generated objects that use it to also fail that check. This causes pessimization because a std::move() of any type using an InplaceOptionalHolder anywhere in its descendants has to do a copy instead.
This problems is caused because:
-
in_place_storageseems to be no-copy/no-move by design, sinceinplace_optional_holderaccess the internal storage directly in its own copy constructor (viagetStorage()orgetObject()), and -
inplace_optional_holder(inplace_optional_holder&&)doesn't access the internal storage, but attempts to move thein_place_storageobject itself, which cannot happen because the point above.
So I'd say, either:
- make
in_place_storagecopyable/movable (and updateinplace_optional_holderto not usegetStorage()/getObject()so much), or - update all
inplace_optional_holderconstructors to usegetStorage()/getObject()like the other constructors.
How to reproduce Compile the following file:
#include <zserio/OptionalHolder.h>
static_assert(std::is_nothrow_move_constructible<zserio::InplaceOptionalHolder<int>>)
Expected behavior The compilation passes because the static assert isn't triggered.
Additional context N/A