Skip to content

Assignment Semantics Issue #2

Closed
@Lotharyx

Description

@Lotharyx

With intrinsic type T, given:

EEPROMStorage<T> first_thing(0, 0);
EEPROMStorage<T> second_thing((sizeof(T) + 1), 0);

Code such as the following:

...
second_thing = first_thing;
...

does not result in the value in first_thing being copied into second_thing, which misled me (an experienced coder) and probably would be very misleading to a novice (common among Arduino users). It in fact appears to cause the checksum of second_thing to become invalid, as evidenced by the constructor reinitializing the default value on the next boot.

Using a temporary variable yields the expected result, e.g.,

...
T temp = first_thing;
second_thing = temp;
...

I suggest that EEPROMStorage<T>::operator=(const EEPROMStorage & rhs) and EEPROMStorage<T>::operator=(const T& rhs) should be equivalent.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions