Skip to content
This repository was archived by the owner on Jun 30, 2022. It is now read-only.
This repository was archived by the owner on Jun 30, 2022. It is now read-only.

std::move implementation is incorrect #12

Closed
@matthijskooijman

Description

@matthijskooijman

This library now contains a stub move implementation:

// Stubb out move for compatibility
template<class T>
T& move(T& t) noexcept {
return t;
}

However, the implementation is incorrect: It simply returns the passed reference unmodified, but should convert it to a rvalue reference, see https://en.cppreference.com/w/cpp/utility/move

It seems this change originated at mike-matera/ArduinoSTL#36, which argues that the AVR compiler does not support move semantics, which is untrue. The compiler itself is just plain gcc, and when enabled with the right -std option, supports all language features of whatever standard used, including rvalue references (&& types). The only bit missing is libstdc++, which for move semantics mostly just means supporting std::move with a proper signature.

With the current std::move signature, this means that implementations that intend to use move semantics for a value will end up making needless copies instead.

A fix for this would be fairly simple, though looking at the docs at https://en.cppreference.com/w/cpp/utility/move would also require adding std::remove_reference.

More generally, though, I wonder if it would not be better to just omit the move function entirely. It is a C++11 feature, and this library mostly implements C++03. Mixing and matching versions like this makes it harder to use other libraries (like https://github.com/hideakitai/ArxTypeTraits) to add the C++11 and newer bits on top of the C++03 bits provided by this library...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions